[MediaPlayer] Added ErrorHandler registration methods for internal use. (#33)
authorcoderhyme <jhyo.kim@samsung.com>
Thu, 18 Jan 2018 09:44:30 +0000 (18:44 +0900)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2018 09:44:30 +0000 (18:44 +0900)
* [MediaPlayer] Added ErrorHandler registration methods for internal use. (#31)

Signed-off-by: coderhyme <jhyo.kim@samsung.com>
* [MediaPlayer] Changed exception message format when the error is unknown.

Signed-off-by: coderhyme <jhyo.kim@samsung.com>
15 files changed:
src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs
src/Tizen.Multimedia.MediaPlayer/Player/AudioEffect.cs
src/Tizen.Multimedia.MediaPlayer/Player/EqualizerBand.cs
src/Tizen.Multimedia.MediaPlayer/Player/MediaBufferSource.cs
src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamConfiguration.cs
src/Tizen.Multimedia.MediaPlayer/Player/MediaStreamSource.cs
src/Tizen.Multimedia.MediaPlayer/Player/MediaUriSource.cs
src/Tizen.Multimedia.MediaPlayer/Player/Player.ErrorHandler.cs [new file with mode: 0644]
src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs
src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs
src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs
src/Tizen.Multimedia.MediaPlayer/Player/PlayerError.cs
src/Tizen.Multimedia.MediaPlayer/Player/PlayerTrackInfo.cs
src/Tizen.Multimedia.MediaPlayer/Player/StreamInfo.cs

index d95e8d5dc1fbe74f1d894b9330a1df3d29258fd4..b9378c8bb24b72265c14c6463a1894209e00bb64 100644 (file)
@@ -179,7 +179,7 @@ internal static partial class Interop
         internal static extern PlayerErrorCode PushMediaStream(IntPtr player, IntPtr packet);
 
         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_info")]
-        internal static extern PlayerErrorCode SetMediaStreamInfo(IntPtr player, int type, IntPtr format);
+        internal static extern PlayerErrorCode SetMediaStreamInfo(IntPtr player, StreamType type, IntPtr format);
 
         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_status_cb")]
         internal static extern PlayerErrorCode SetMediaStreamBufferStatusCb(IntPtr player, StreamType type,
@@ -249,16 +249,18 @@ internal static partial class Interop
         internal static extern PlayerErrorCode UnsetVideoStreamChangedCb(IntPtr player);
 
         [DllImport(Libraries.Player, EntryPoint = "player_get_track_count")]
-        internal static extern PlayerErrorCode GetTrackCount(IntPtr player, int type, out int count);
+        internal static extern PlayerErrorCode GetTrackCount(IntPtr player, StreamType type, out int count);
 
         [DllImport(Libraries.Player, EntryPoint = "player_select_track")]
-        internal static extern PlayerErrorCode SelectTrack(IntPtr player, int type, int index);
+        internal static extern PlayerErrorCode SelectTrack(IntPtr player, StreamType type, int index);
 
         [DllImport(Libraries.Player, EntryPoint = "player_get_current_track")]
-        internal static extern PlayerErrorCode GetCurrentTrack(IntPtr player, int type, out int index);
+        internal static extern PlayerErrorCode GetCurrentTrack(IntPtr player, StreamType type,
+            out int index);
 
         [DllImport(Libraries.Player, EntryPoint = "player_get_track_language_code")]
-        internal static extern PlayerErrorCode GetTrackLanguageCode(IntPtr player, int type, int index, out IntPtr code);
+        internal static extern PlayerErrorCode GetTrackLanguageCode(IntPtr player, StreamType type,
+            int index, out IntPtr code);
     }
 
     internal class PlayerHandle : SafeHandle
index fbc09e02078d07f88d04fdaf727b4d3759f414a2..d7a2e84b1d8cae4b4f587fc5f55b815f0355f9fd 100644 (file)
@@ -34,7 +34,7 @@ namespace Tizen.Multimedia
             bool available = false;
 
             Native.EqualizerIsAvailable(Player.Handle, out available).
-                ThrowIfFailed("Failed to initialize the AudioEffect");
+                ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
 
             IsAvailable = available;
 
@@ -45,12 +45,12 @@ namespace Tizen.Multimedia
 
             int count = 0;
             Native.GetEqualizerBandsCount(Player.Handle, out count).
-                ThrowIfFailed("Failed to initialize the AudioEffect");
+                ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
 
             int min = 0;
             int max = 0;
             Native.GetEqualizerLevelRange(Player.Handle, out min, out max).
-                ThrowIfFailed("Failed to initialize the AudioEffect");
+                ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
 
             Count = count;
             BandLevelRange = new Range(min, max);
@@ -100,7 +100,7 @@ namespace Tizen.Multimedia
             Player.ValidateNotDisposed();
 
             Native.EqualizerClear(Player.Handle).
-                ThrowIfFailed("Failed to clear equalizer effect");
+                ThrowIfFailed(Player, "Failed to clear equalizer effect");
         }
 
         /// <summary>
index 8e66500d5452c59c248ef6f58d75fcf084a22475..86cdc73e1ac5b1dd08e23c8d5b7abae65b8e5900 100644 (file)
@@ -37,14 +37,11 @@ namespace Tizen.Multimedia
             _owner = owner;
             _index = index;
 
-            int frequency = 0;
-            int range = 0;
+            Native.GetEqualizerBandFrequency(_owner.Player.Handle, _index, out var frequency).
+                ThrowIfFailed(_owner.Player, "Failed to initialize equalizer band");
 
-            Native.GetEqualizerBandFrequency(_owner.Player.Handle, _index, out frequency).
-                ThrowIfFailed("Failed to initialize equalizer band");
-
-            Native.GetEqualizerBandFrequencyRange(_owner.Player.Handle, _index, out range).
-                ThrowIfFailed("Failed to initialize equalizer band");
+            Native.GetEqualizerBandFrequencyRange(_owner.Player.Handle, _index, out var range).
+                ThrowIfFailed(_owner.Player, "Failed to initialize equalizer band");
 
             Frequency = frequency;
             FrequencyRange = range;
@@ -66,9 +63,9 @@ namespace Tizen.Multimedia
             {
                 _owner.Player.ValidateNotDisposed();
 
-                int value = 0;
-                Native.GetEqualizerBandLevel(_owner.Player.Handle, _index, out value).
-                    ThrowIfFailed("Failed to get the level of the equalizer band");
+                Native.GetEqualizerBandLevel(_owner.Player.Handle, _index, out var value).
+                    ThrowIfFailed(_owner.Player, "Failed to get the level of the equalizer band");
+
                 Log.Info(PlayerLog.Tag, "get level : " + value);
                 return value;
             }
@@ -85,7 +82,7 @@ namespace Tizen.Multimedia
                 }
 
                 Native.SetEqualizerBandLevel(_owner.Player.Handle, _index, value).
-                    ThrowIfFailed("Failed to set the level of the equalizer band");
+                    ThrowIfFailed(_owner.Player, "Failed to set the level of the equalizer band");
             }
         }
 
index baad627292e49ad4efc793eff0aa8b64a7e69135..0ad90e3ff76396dc8080d121caf13130225dee0f 100644 (file)
@@ -84,22 +84,19 @@ namespace Tizen.Multimedia
         {
             if (buffer == null)
             {
-                Log.Error(PlayerLog.Tag, "invalid buffer");
                 throw new ArgumentNullException(nameof(buffer));
             }
+
             if (offset < 0)
             {
-                Log.Error(PlayerLog.Tag, "invalid offset : " + offset);
                 throw new ArgumentOutOfRangeException(nameof(offset), offset, "offset can't be less than zero.");
             }
             if (length <= 0)
             {
-                Log.Error(PlayerLog.Tag, "invalid length : " + length);
                 throw new ArgumentOutOfRangeException(nameof(length), length, "length can't be equal to or less than zero.");
             }
             if (length + offset > buffer.Length)
             {
-                Log.Error(PlayerLog.Tag, "invalid total length : " + (int)(length + offset));
                 throw new ArgumentOutOfRangeException($"length + offset can't be greater than the length of the { nameof(buffer) }.");
             }
 
@@ -140,7 +137,7 @@ namespace Tizen.Multimedia
         internal override void OnAttached(Player player)
         {
             NativePlayer.SetMemoryBuffer(player.Handle, _buffer, _buffer.Length).
-                ThrowIfFailed("Failed to set the memory buffer");
+                ThrowIfFailed(player, "Failed to set the memory buffer");
         }
     }
 }
index 172cba5a58d857680ca23df76ebff9f29e2f6caa..c8d19defb1468764bac7ed50539d1b895851501d 100644 (file)
@@ -88,7 +88,7 @@ namespace Tizen.Multimedia
                 }
 
                 NativePlayer.SetMediaStreamBufferMaxSize(_owner.Player.Handle, _streamType, value).
-                    ThrowIfFailed("Failed to set the buffer max size");
+                    ThrowIfFailed(_owner.Player, "Failed to set the buffer max size");
 
                 _bufferMaxSize = value;
             }
@@ -125,7 +125,7 @@ namespace Tizen.Multimedia
                 }
 
                 NativePlayer.SetMediaStreamBufferMinThreshold(_owner.Player.Handle, _streamType, value).
-                    ThrowIfFailed("Failed to set the buffer minimum threshold");
+                    ThrowIfFailed(_owner.Player, "Failed to set the buffer minimum threshold");
 
                 _threshold = value;
             }
@@ -145,10 +145,10 @@ namespace Tizen.Multimedia
             }
 
             NativePlayer.SetMediaStreamBufferMaxSize(player.Handle, _streamType, _bufferMaxSize).
-                ThrowIfFailed("Failed to initialize the media stream configuration");
+                ThrowIfFailed(player, "Failed to initialize the media stream configuration");
 
             NativePlayer.SetMediaStreamBufferMinThreshold(player.Handle, _streamType, _threshold).
-                ThrowIfFailed("Failed to initialize the media stream configuration");
+                ThrowIfFailed(player, "Failed to initialize the media stream configuration");
         }
 
         internal void OnPlayerUnset(Player player)
index 032de6718c39a9b195797f9d38ea5e1f75a8a5fa..b078642ee63e371022511767858c40ecab18640a 100644 (file)
@@ -243,7 +243,7 @@ namespace Tizen.Multimedia
             _player.ValidatePlayerState(PlayerState.Paused, PlayerState.Playing, PlayerState.Ready);
 
             NativePlayer.PushMediaStream(_player.Handle, packet.GetHandle()).
-                ThrowIfFailed("Failed to push the packet to the player");
+                ThrowIfFailed(_player, "Failed to push the packet to the player");
         }
 
         private void SetMediaStreamInfo(StreamType streamType, MediaFormat mediaFormat)
@@ -259,8 +259,9 @@ namespace Tizen.Multimedia
             try
             {
                 ptr = mediaFormat.AsNativeHandle();
-                NativePlayer.SetMediaStreamInfo(_player.Handle, (int)streamType, ptr).
-                    ThrowIfFailed("Failed to set the media stream info");
+
+                NativePlayer.SetMediaStreamInfo(_player.Handle, streamType, ptr).
+                    ThrowIfFailed(_player, "Failed to set the media stream info");
             }
             finally
             {
index 3fcace732d322f40a0469802cc908fbaedf34dfd..240b7a37f0344e4198188bf49bc07764831bd3bb 100644 (file)
@@ -52,7 +52,8 @@ namespace Tizen.Multimedia
 
         internal override void OnAttached(Player player)
         {
-            NativePlayer.SetUri(player.Handle, Uri).ThrowIfFailed("Failed to set the source with specified uri");
+            NativePlayer.SetUri(player.Handle, Uri).
+                ThrowIfFailed(player, "Failed to set the source with specified uri");
         }
     }
 }
diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.ErrorHandler.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.ErrorHandler.cs
new file mode 100644 (file)
index 0000000..6f6ddc9
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+
+namespace Tizen.Multimedia
+{
+    public partial class Player
+    {
+        private static List<Action<Player, int, string>> _errorHandlers;
+
+        private static object _errorHandlerLock = new object();
+
+        /// <summary>
+        /// This method supports the product infrastructure and is not intended to be used directly from application code.
+        /// </summary>
+        /// <since_tizen> 4 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected static void AddErrorHandler(Action<Player, int, string> errorHandler)
+        {
+            if (errorHandler == null)
+            {
+                throw new ArgumentNullException(nameof(errorHandler));
+            }
+
+            lock (_errorHandlerLock)
+            {
+                if (_errorHandlers == null)
+                {
+                    _errorHandlers = new List<Action<Player, int, string>>();
+                }
+
+                _errorHandlers.Add(errorHandler);
+            }
+        }
+
+        /// <summary>
+        /// This method supports the product infrastructure and is not intended to be used directly from application code.
+        /// </summary>
+        /// <since_tizen> 4 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected static void RemoveErrorHandler(Action<Player, int, string> errorHandler)
+        {
+            lock (_errorHandlerLock)
+            {
+                _errorHandlers?.Remove(errorHandler);
+            }
+        }
+
+        internal static void NotifyError(Player player, int errorCode, string message)
+        {
+            if (_errorHandlers == null)
+            {
+                return;
+            }
+
+            lock (_errorHandlerLock)
+            {
+                foreach (var handler in _errorHandlers)
+                {
+                    handler(player, errorCode, message);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
index 23e386a7559214b62d91f77744e0d683f3598210..580b2abaf54b91645fcfd37d4f905ef6f56d72f9 100644 (file)
@@ -112,12 +112,12 @@ namespace Tizen.Multimedia
         {
             _subtitleUpdatedCallback = (duration, text, _) =>
             {
-                Log.Debug(PlayerLog.Tag, "duration : " + duration + ", text : " + text);
+                Log.Debug(PlayerLog.Tag, $"duration : {duration}, text : {text}");
                 SubtitleUpdated?.Invoke(this, new SubtitleUpdatedEventArgs(duration, text));
             };
 
             NativePlayer.SetSubtitleUpdatedCb(Handle, _subtitleUpdatedCallback).
-                ThrowIfFailed("Failed to initialize the player");
+                ThrowIfFailed(this, "Failed to initialize the player");
         }
 
         private void RegisterPlaybackCompletedCallback()
@@ -128,7 +128,7 @@ namespace Tizen.Multimedia
                 PlaybackCompleted?.Invoke(this, EventArgs.Empty);
             };
             NativePlayer.SetCompletedCb(Handle, _playbackCompletedCallback).
-                ThrowIfFailed("Failed to set PlaybackCompleted");
+                ThrowIfFailed(this, "Failed to set PlaybackCompleted");
         }
 
         private void RegisterPlaybackInterruptedCallback()
@@ -145,12 +145,12 @@ namespace Tizen.Multimedia
                     OnUnprepared();
                 }
 
-                Log.Warn(PlayerLog.Tag, "interrupted reason : " + code);
+                Log.Warn(PlayerLog.Tag, $"interrupted reason : {code}");
                 PlaybackInterrupted?.Invoke(this, new PlaybackInterruptedEventArgs(code));
             };
 
             NativePlayer.SetInterruptedCb(Handle, _playbackInterruptedCallback).
-                ThrowIfFailed("Failed to set PlaybackInterrupted");
+                ThrowIfFailed(this, "Failed to set PlaybackInterrupted");
         }
 
         private void RegisterErrorOccurredCallback()
@@ -163,7 +163,7 @@ namespace Tizen.Multimedia
             };
 
             NativePlayer.SetErrorCb(Handle, _playbackErrorCallback).
-                ThrowIfFailed("Failed to set PlaybackError");
+                ThrowIfFailed(this, "Failed to set PlaybackError");
         }
 
         #region VideoFrameDecoded event
@@ -217,7 +217,7 @@ namespace Tizen.Multimedia
             };
 
             NativePlayer.SetVideoFrameDecodedCb(Handle, _videoFrameDecodedCallback).
-                ThrowIfFailed("Failed to register the VideoFrameDecoded");
+                ThrowIfFailed(this, "Failed to register the VideoFrameDecoded");
         }
         #endregion
 
@@ -225,14 +225,13 @@ namespace Tizen.Multimedia
         {
             _videoStreamChangedCallback = (width, height, fps, bitrate, _) =>
             {
-                Log.Debug(PlayerLog.Tag, "height : " + height + ", width : " + width
-                + ", fps : " + fps + ", bitrate : " + bitrate);
+                Log.Debug(PlayerLog.Tag, $"height={height}, width={width}, fps={fps}, bitrate={bitrate}");
 
                 VideoStreamChanged?.Invoke(this, new VideoStreamChangedEventArgs(height, width, fps, bitrate));
             };
 
             NativePlayer.SetVideoStreamChangedCb(Handle, _videoStreamChangedCallback).
-                ThrowIfFailed("Failed to set the video stream changed callback");
+                ThrowIfFailed(this, "Failed to set the video stream changed callback");
         }
 
         private void RegisterBufferingCallback()
@@ -240,11 +239,12 @@ namespace Tizen.Multimedia
             _bufferingProgressCallback = (percent, _) =>
             {
                 Log.Debug(PlayerLog.Tag, $"Buffering callback with percent { percent }");
+
                 BufferingProgressChanged?.Invoke(this, new BufferingProgressChangedEventArgs(percent));
             };
 
             NativePlayer.SetBufferingCb(Handle, _bufferingProgressCallback).
-                ThrowIfFailed("Failed to set BufferingProgress");
+                ThrowIfFailed(this, "Failed to set BufferingProgress");
         }
 
         private void RegisterMediaStreamBufferStatusCallback()
@@ -253,6 +253,7 @@ namespace Tizen.Multimedia
             {
                 Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status));
                 Log.Debug(PlayerLog.Tag, "audio buffer status : " + status);
+
                 MediaStreamAudioBufferStatusChanged?.Invoke(this,
                     new MediaStreamBufferStatusChangedEventArgs(status));
             };
@@ -260,6 +261,7 @@ namespace Tizen.Multimedia
             {
                 Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status));
                 Log.Debug(PlayerLog.Tag, "video buffer status : " + status);
+
                 MediaStreamVideoBufferStatusChanged?.Invoke(this,
                     new MediaStreamBufferStatusChangedEventArgs(status));
             };
@@ -272,7 +274,7 @@ namespace Tizen.Multimedia
             NativePlayer.MediaStreamBufferStatusCallback cb)
         {
             NativePlayer.SetMediaStreamBufferStatusCb(Handle, streamType, cb).
-                ThrowIfFailed("Failed to SetMediaStreamBufferStatus");
+                ThrowIfFailed(this, "Failed to SetMediaStreamBufferStatus");
         }
 
         private void RegisterMediaStreamSeekCallback()
@@ -295,7 +297,7 @@ namespace Tizen.Multimedia
         private void RegisterMediaStreamSeekCallback(StreamType streamType, NativePlayer.MediaStreamSeekCallback cb)
         {
             NativePlayer.SetMediaStreamSeekCb(Handle, streamType, cb).
-                ThrowIfFailed("Failed to SetMediaStreamSeek");
+                ThrowIfFailed(this, "Failed to SetMediaStreamSeek");
         }
     }
 }
index 0ea4cdd53229685305e082ab91392d7a63e86925..e2a4742accc8b713c239674b859406a34db2835f 100644 (file)
@@ -27,14 +27,6 @@ namespace Tizen.Multimedia
     /// <since_tizen> 3 </since_tizen>
     public partial class Player
     {
-        private void RetrieveProperties()
-        {
-            NativePlayer.GetAudioLatencyMode(Handle, out _audioLatencyMode).
-                ThrowIfFailed("Failed to initialize the player");
-
-            NativePlayer.IsLooping(Handle, out _isLooping).ThrowIfFailed("Failed to initialize the player");
-        }
-
         /// <summary>
         /// Gets the native handle of the player.
         /// </summary>
@@ -66,7 +58,6 @@ namespace Tizen.Multimedia
         {
             get
             {
-                Log.Info(PlayerLog.Tag, "get cookie : " + _cookie);
                 return _cookie;
             }
             set
@@ -79,7 +70,7 @@ namespace Tizen.Multimedia
                 }
 
                 NativePlayer.SetStreamingCookie(Handle, value, value.Length).
-                    ThrowIfFailed("Failed to set the cookie to the player");
+                    ThrowIfFailed(this, "Failed to set the cookie to the player");
 
                 _cookie = value;
             }
@@ -97,7 +88,6 @@ namespace Tizen.Multimedia
         {
             get
             {
-                Log.Info(PlayerLog.Tag, "get useragent : " + _userAgent);
                 return _userAgent;
             }
             set
@@ -110,7 +100,7 @@ namespace Tizen.Multimedia
                 }
 
                 NativePlayer.SetStreamingUserAgent(Handle, value, value.Length).
-                    ThrowIfFailed("Failed to set the user agent to the player");
+                    ThrowIfFailed(this, "Failed to set the user agent to the player");
 
                 _userAgent = value;
             }
@@ -134,7 +124,8 @@ namespace Tizen.Multimedia
                     return PlayerState.Preparing;
                 }
 
-                NativePlayer.GetState(Handle, out var state).ThrowIfFailed("Failed to retrieve the state of the player");
+                NativePlayer.GetState(Handle, out var state).
+                    ThrowIfFailed(this, "Failed to retrieve the state of the player");
 
                 Debug.Assert(Enum.IsDefined(typeof(PlayerState), state));
 
@@ -142,8 +133,6 @@ namespace Tizen.Multimedia
             }
         }
 
-        private AudioLatencyMode _audioLatencyMode;
-
         /// <summary>
         /// Gets or sets the audio latency mode.
         /// </summary>
@@ -160,28 +149,22 @@ namespace Tizen.Multimedia
         {
             get
             {
-                Log.Info(PlayerLog.Tag, "get audio latency mode : " + _audioLatencyMode);
-                return _audioLatencyMode;
+                NativePlayer.GetAudioLatencyMode(Handle, out var value).
+                    ThrowIfFailed(this, "Failed to get the audio latency mode of the player");
+
+                return value;
             }
             set
             {
                 ValidateNotDisposed();
 
-                if (_audioLatencyMode == value)
-                {
-                    return;
-                }
                 ValidationUtil.ValidateEnum(typeof(AudioLatencyMode), value);
 
                 NativePlayer.SetAudioLatencyMode(Handle, value).
-                    ThrowIfFailed("Failed to set the audio latency mode of the player");
-
-                _audioLatencyMode = value;
+                    ThrowIfFailed(this, "Failed to set the audio latency mode of the player");
             }
         }
 
-        private bool _isLooping;
-
         /// <summary>
         /// Gets or sets the looping state.
         /// </summary>
@@ -192,25 +175,22 @@ namespace Tizen.Multimedia
         {
             get
             {
-                Log.Info(PlayerLog.Tag, "get looping : " + _isLooping);
-                return _isLooping;
+                NativePlayer.IsLooping(Handle, out var value).
+                    ThrowIfFailed(this, "Failed to get the looping state of the player");
+
+                return value;
             }
             set
             {
                 ValidateNotDisposed();
 
-                if (_isLooping == value)
-                {
-                    return;
-                }
-
-                NativePlayer.SetLooping(Handle, value).ThrowIfFailed("Failed to set the looping state of the player");
-
-                _isLooping = value;
+                NativePlayer.SetLooping(Handle, value).
+                    ThrowIfFailed(this, "Failed to set the looping state of the player");
             }
         }
 
         #region Display methods
+
         /// <summary>
         /// Gets the display settings.
         /// </summary>
@@ -387,8 +367,8 @@ namespace Tizen.Multimedia
         {
             get
             {
-                bool value = false;
-                NativePlayer.IsMuted(Handle, out value).ThrowIfFailed("Failed to get the mute state of the player");
+                NativePlayer.IsMuted(Handle, out var value).
+                    ThrowIfFailed(this, "Failed to get the mute state of the player");
 
                 Log.Info(PlayerLog.Tag, "get mute : " + value);
 
@@ -396,7 +376,7 @@ namespace Tizen.Multimedia
             }
             set
             {
-                NativePlayer.SetMute(Handle, value).ThrowIfFailed("Failed to set the mute state of the player");
+                NativePlayer.SetMute(Handle, value).ThrowIfFailed(this, "Failed to set the mute state of the player");
             }
         }
 
@@ -417,7 +397,8 @@ namespace Tizen.Multimedia
             {
                 float value = 0.0F;
                 NativePlayer.GetVolume(Handle, out value, out value).
-                    ThrowIfFailed("Failed to get the volume of the player");
+                    ThrowIfFailed(this, "Failed to get the volume of the player");
+
                 return value;
             }
             set
@@ -429,7 +410,7 @@ namespace Tizen.Multimedia
                 }
 
                 NativePlayer.SetVolume(Handle, value, value).
-                    ThrowIfFailed("Failed to set the volume of the player");
+                    ThrowIfFailed(this, "Failed to set the volume of the player");
             }
         }
     }
index 466dcb9fa3236085b6ca5ea30ba86265b24cc86b..ff61ee1a8fe9904592ed36bd34ee633f9fdb7837 100644 (file)
@@ -47,12 +47,10 @@ namespace Tizen.Multimedia
         /// <since_tizen> 3 </since_tizen>
         public Player()
         {
-            NativePlayer.Create(out _handle).ThrowIfFailed("Failed to create player");
+            NativePlayer.Create(out _handle).ThrowIfFailed(null, "Failed to create player");
 
             Debug.Assert(_handle != null);
 
-            RetrieveProperties();
-
             if (Features.IsSupported(PlayerFeatures.AudioEffect))
             {
                 _audioEffect = new AudioEffect(this);
@@ -154,7 +152,7 @@ namespace Tizen.Multimedia
             int start = 0;
             int current = 0;
             NativePlayer.GetStreamingDownloadProgress(Handle, out start, out current).
-                ThrowIfFailed("Failed to get download progress");
+                ThrowIfFailed(this, "Failed to get download progress");
 
             Log.Info(PlayerLog.Tag, "get download progress : " + start + ", " + current);
 
@@ -193,7 +191,7 @@ namespace Tizen.Multimedia
             }
 
             NativePlayer.SetSubtitlePath(Handle, path).
-                ThrowIfFailed("Failed to set the subtitle path to the player");
+                ThrowIfFailed(this, "Failed to set the subtitle path to the player");
         }
 
         /// <summary>
@@ -208,7 +206,7 @@ namespace Tizen.Multimedia
             ValidatePlayerState(PlayerState.Idle);
 
             NativePlayer.SetSubtitlePath(Handle, null).
-                ThrowIfFailed("Failed to clear the subtitle of the player");
+                ThrowIfFailed(this, "Failed to clear the subtitle of the player");
         }
 
         /// <summary>
@@ -235,12 +233,12 @@ namespace Tizen.Multimedia
                 throw new InvalidOperationException("No subtitle set");
             }
 
-            err.ThrowIfFailed("Failed to the subtitle offset of the player");
+            err.ThrowIfFailed(this, "Failed to the subtitle offset of the player");
         }
 
         private void Prepare()
         {
-            NativePlayer.Prepare(Handle).ThrowIfFailed("Failed to prepare the player");
+            NativePlayer.Prepare(Handle).ThrowIfFailed(this, "Failed to prepare the player");
         }
 
         /// <summary>
@@ -271,7 +269,7 @@ namespace Tizen.Multimedia
 
             ValidatePlayerState(PlayerState.Idle);
 
-            SetDisplay(_display).ThrowIfFailed("Failed to configure display of the player");
+            SetDisplay(_display).ThrowIfFailed(this, "Failed to configure display of the player");
 
             SetPreparing();
 
@@ -315,7 +313,7 @@ namespace Tizen.Multimedia
             }
             ValidatePlayerState(PlayerState.Ready, PlayerState.Paused, PlayerState.Playing);
 
-            NativePlayer.Unprepare(Handle).ThrowIfFailed("Failed to unprepare the player");
+            NativePlayer.Unprepare(Handle).ThrowIfFailed(this, "Failed to unprepare the player");
 
             OnUnprepared();
         }
@@ -357,7 +355,7 @@ namespace Tizen.Multimedia
             }
             ValidatePlayerState(PlayerState.Ready, PlayerState.Paused);
 
-            NativePlayer.Start(Handle).ThrowIfFailed("Failed to start the player");
+            NativePlayer.Start(Handle).ThrowIfFailed(this, "Failed to start the player");
         }
 
         /// <summary>
@@ -381,7 +379,7 @@ namespace Tizen.Multimedia
             }
             ValidatePlayerState(PlayerState.Paused, PlayerState.Playing);
 
-            NativePlayer.Stop(Handle).ThrowIfFailed("Failed to stop the player");
+            NativePlayer.Stop(Handle).ThrowIfFailed(this, "Failed to stop the player");
         }
 
         /// <summary>
@@ -405,7 +403,7 @@ namespace Tizen.Multimedia
 
             ValidatePlayerState(PlayerState.Playing);
 
-            NativePlayer.Pause(Handle).ThrowIfFailed("Failed to pause the player");
+            NativePlayer.Pause(Handle).ThrowIfFailed(this, "Failed to pause the player");
         }
 
         private MediaSource _source;
@@ -471,7 +469,7 @@ namespace Tizen.Multimedia
             using (var cbKeeper = ObjectKeeper.Get(cb))
             {
                 NativePlayer.CaptureVideo(Handle, cb)
-                    .ThrowIfFailed("Failed to capture the video");
+                    .ThrowIfFailed(this, "Failed to capture the video");
 
                 return await t.Task;
             }
@@ -493,7 +491,7 @@ namespace Tizen.Multimedia
             int playPosition = 0;
 
             NativePlayer.GetPlayPosition(Handle, out playPosition).
-                ThrowIfFailed("Failed to get the play position of the player");
+                ThrowIfFailed(this, "Failed to get the play position of the player");
 
             Log.Info(PlayerLog.Tag, "get play position : " + playPosition);
 
@@ -515,7 +513,7 @@ namespace Tizen.Multimedia
             {
                 Log.Error(PlayerLog.Tag, "Failed to set play position, " + (PlayerError)ret);
             }
-            ret.ThrowIfFailed("Failed to set play position");
+            ret.ThrowIfFailed(this, "Failed to set play position");
         }
 
         /// <summary>
@@ -588,7 +586,7 @@ namespace Tizen.Multimedia
 
             ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-            NativePlayer.SetPlaybackRate(Handle, rate).ThrowIfFailed("Failed to set the playback rate.");
+            NativePlayer.SetPlaybackRate(Handle, rate).ThrowIfFailed(this, "Failed to set the playback rate.");
         }
 
         /// <summary>
@@ -637,7 +635,7 @@ namespace Tizen.Multimedia
                 throw new NotSupportedException("The specified policy is not supported on the current system.");
             }
 
-            ret.ThrowIfFailed("Failed to set the audio stream policy to the player");
+            ret.ThrowIfFailed(this, "Failed to set the audio stream policy to the player");
         }
         #endregion
 
@@ -661,13 +659,5 @@ namespace Tizen.Multimedia
         }
 
         #endregion
-
-        /// <summary>
-        /// This method supports the product infrastructure and is not intended to be used directly from application code.
-        /// </summary>
-        /// <since_tizen> 4 </since_tizen>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected static Exception GetException(int errorCode, string message) =>
-            ((PlayerErrorCode)errorCode).GetException(message);
     }
 }
index 4aa2254419add115e859427d9b57e592d8138875..6ae5419911551aaef5ea81bb58a0b38b441c0ee8 100644 (file)
@@ -65,7 +65,7 @@ namespace Tizen.Multimedia
             get
             {
                 Native.GetMode(Player.Handle, out var value).
-                    ThrowIfFailed("Failed to get display mode");
+                    ThrowIfFailed(Player, "Failed to get display mode");
 
                 return value;
             }
@@ -74,7 +74,7 @@ namespace Tizen.Multimedia
                 ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
 
                 Native.SetMode(Player.Handle, value).
-                    ThrowIfFailed("Failed to set display mode");
+                    ThrowIfFailed(Player, "Failed to set display mode");
             }
         }
 
@@ -92,13 +92,14 @@ namespace Tizen.Multimedia
             get
             {
                 Native.IsVisible(Player.Handle, out var value).
-                    ThrowIfFailed("Failed to get the visible state of the display");
+                    ThrowIfFailed(Player, "Failed to get the visible state of the display");
 
                 return value;
             }
             set
             {
-                Native.SetVisible(Player.Handle, value).ThrowIfFailed("Failed to set the visible state of the display");
+                Native.SetVisible(Player.Handle, value).ThrowIfFailed(
+                    Player, "Failed to set the visible state of the display");
             }
         }
 
@@ -118,7 +119,7 @@ namespace Tizen.Multimedia
             get
             {
                 Native.GetRotation(Player.Handle, out var value).
-                    ThrowIfFailed("Failed to get the rotation state of the display");
+                    ThrowIfFailed(Player, "Failed to get the rotation state of the display");
 
                 return value;
             }
@@ -127,7 +128,7 @@ namespace Tizen.Multimedia
                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
 
                 Native.SetRotation(Player.Handle, value).
-                    ThrowIfFailed("Failed to set the rotation state of the display");
+                    ThrowIfFailed(Player, "Failed to set the rotation state of the display");
             }
         }
 
@@ -165,7 +166,7 @@ namespace Tizen.Multimedia
             }
 
             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
-                ThrowIfFailed("Failed to set the roi");
+                ThrowIfFailed(Player, "Failed to set the roi");
         }
     }
 }
index bb5a84d0cb6c8cd4a58e4ffc14647e90f3873a8e..ff48365214e95efad4a21bfd8e51f679bc428d8a 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using System.IO;
 using Tizen.Internals.Errors;
@@ -52,14 +53,24 @@ namespace Tizen.Multimedia
 
     internal static class PlayerErrorCodeExtensions
     {
-        internal static void ThrowIfFailed(this PlayerErrorCode err, string message)
+        internal static void ThrowIfFailed(this PlayerErrorCode err, Player player, string message)
         {
             if (err == PlayerErrorCode.None)
             {
                 return;
             }
 
-            throw err.GetException(message);
+            var ex = err.GetException(message);
+
+            if (ex == null)
+            {
+                // Notify only when it can't be handled.
+                Player.NotifyError(player, (int)err, message);
+
+                throw new InvalidOperationException($"{message} : Unknown error({err.ToString()}).");
+            }
+
+            throw ex;
         }
 
         internal static Exception GetException(this PlayerErrorCode err, string message)
@@ -118,10 +129,9 @@ namespace Tizen.Multimedia
 
                 case PlayerErrorCode.NotSupportedVideoCodec:
                     throw new CodecNotSupportedException(CodecKind.Video);
-
             }
 
-            throw new InvalidOperationException(msg);
+            return null;
         }
     }
 
index 76da51341c0963b887003fbfbf39ff8f3bc564d8..f594b89c79284e48d8a190eaf183a26403d59c50 100644 (file)
@@ -28,15 +28,14 @@ namespace Tizen.Multimedia
     /// <since_tizen> 3 </since_tizen>
     public class PlayerTrackInfo
     {
-        private readonly int _streamType;
+        private readonly StreamType _streamType;
         private readonly Player _owner;
 
         internal PlayerTrackInfo(Player player, StreamType streamType)
         {
             Debug.Assert(player != null);
 
-            Log.Debug(PlayerLog.Tag, "streamType : " + streamType);
-            _streamType = (int)streamType;
+            _streamType = streamType;
             _owner = player;
         }
 
@@ -55,10 +54,11 @@ namespace Tizen.Multimedia
         {
             _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-            int count = 0;
-            NativePlayer.GetTrackCount(_owner.Handle, _streamType, out count).
-                ThrowIfFailed("Failed to get count of the track");
+            NativePlayer.GetTrackCount(_owner.Handle, _streamType, out var count).
+                ThrowIfFailed(_owner, "Failed to get count of the track");
+
             Log.Info(PlayerLog.Tag, "get count : " + count);
+
             return count;
         }
 
@@ -85,9 +85,8 @@ namespace Tizen.Multimedia
 
             if (index < 0 || GetCount() <= index)
             {
-                Log.Error(PlayerLog.Tag, "invalid index");
                 throw new ArgumentOutOfRangeException(nameof(index), index,
-                    $"valid index range is 0 <= x < {nameof(GetCount)}(), but got { index }.");
+                    $"Valid index range is 0 <= x < {nameof(GetCount)}(), but got { index }.");
             }
 
             IntPtr code = IntPtr.Zero;
@@ -95,7 +94,7 @@ namespace Tizen.Multimedia
             try
             {
                 NativePlayer.GetTrackLanguageCode(_owner.Handle, _streamType, index, out code).
-                    ThrowIfFailed("Failed to get the selected language of the player");
+                    ThrowIfFailed(_owner, "Failed to get the selected language of the player");
 
                 string result = Marshal.PtrToStringAnsi(code);
 
@@ -135,10 +134,8 @@ namespace Tizen.Multimedia
             {
                 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-                int value = 0;
-
-                NativePlayer.GetCurrentTrack(_owner.Handle, _streamType, out value).
-                    ThrowIfFailed("Failed to get the selected index of the player");
+                NativePlayer.GetCurrentTrack(_owner.Handle, _streamType, out var value).
+                    ThrowIfFailed(_owner, "Failed to get the selected index of the player");
                 Log.Debug(PlayerLog.Tag, "get selected index : " + value);
                 return value;
             }
@@ -146,15 +143,14 @@ namespace Tizen.Multimedia
             {
                 if (value < 0 || GetCount() <= value)
                 {
-                    Log.Error(PlayerLog.Tag, "invalid index");
                     throw new ArgumentOutOfRangeException(nameof(value), value,
-                        $"valid index range is 0 <= x < {nameof(GetCount)}(), but got { value }.");
+                        $"Valid index range is 0 <= x < {nameof(GetCount)}(), but got { value }.");
                 }
 
                 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
                 NativePlayer.SelectTrack(_owner.Handle, _streamType, value).
-                    ThrowIfFailed("Failed to set the selected index of the player");
+                    ThrowIfFailed(_owner, "Failed to set the selected index of the player");
             }
         }
     }
index ab0481d915754c923963baa41a31d098ae240731..a38079fa149a82fc7d77a7ed64d5bb63c04929cb 100644 (file)
@@ -37,7 +37,8 @@ namespace Tizen.Multimedia
             SampleRate = sampleRate;
             Channels = channels;
             BitRate = bitRate;
-            Log.Debug(PlayerLog.Tag, "sampleRate : " + sampleRate + ", channels : " + channels + ", bitRate : " + bitRate);
+
+            Log.Debug(PlayerLog.Tag, $"sampleRate={sampleRate}, channels={channels}, bitRate={bitRate}");
         }
 
         /// <summary>
@@ -99,8 +100,7 @@ namespace Tizen.Multimedia
             Fps = fps;
             BitRate = bitRate;
             Size = size;
-            Log.Debug(PlayerLog.Tag, "fps : " + fps + ", bitrate : " + bitRate +
-                ", width : " + size.Width + ", height : " + size.Height);
+            Log.Debug(PlayerLog.Tag, $"fps={fps}, bitrate={bitRate}, size=({size})");
         }
         /// <summary>
         /// Initializes a new instance of the VideoStreamProperties struct with the specified fps, bit rate, width, and height.
@@ -111,12 +111,8 @@ namespace Tizen.Multimedia
         /// <param name="height">The height of the stream.</param>
         /// <since_tizen> 3 </since_tizen>
         public VideoStreamProperties(int fps, int bitRate, int width, int height)
+            : this(fps, bitRate, new Size(width, height))
         {
-            Fps = fps;
-            BitRate = bitRate;
-            Size = new Size(width, height);
-            Log.Debug(PlayerLog.Tag, "fps : " + fps + ", bitrate : " + bitRate +
-                ", width : " + width + ", height : " + height);
         }
 
         /// <summary>
@@ -190,11 +186,10 @@ namespace Tizen.Multimedia
             Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
             NativePlayer.GetAlbumArt(Player.Handle, out var art, out var size).
-                ThrowIfFailed("Failed to get the album art");
+                ThrowIfFailed(Player, "Failed to get the album art");
 
             if (art == IntPtr.Zero || size == 0)
             {
-                Log.Error(PlayerLog.Tag, "art is null or size is 0 : " + size);
                 return null;
             }
 
@@ -212,7 +207,7 @@ namespace Tizen.Multimedia
             try
             {
                 NativePlayer.GetCodecInfo(Player.Handle, out audioPtr, out videoPtr).
-                    ThrowIfFailed("Failed to get codec info");
+                    ThrowIfFailed(Player, "Failed to get codec info");
 
                 if (audioInfo)
                 {
@@ -271,9 +266,8 @@ namespace Tizen.Multimedia
         {
             Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-            int duration = 0;
-            NativePlayer.GetDuration(Player.Handle, out duration).
-                ThrowIfFailed("Failed to get the duration");
+            NativePlayer.GetDuration(Player.Handle, out var duration).
+                ThrowIfFailed(Player, "Failed to get the duration");
 
             Log.Info(PlayerLog.Tag, "get duration : " + duration);
             return duration;
@@ -298,12 +292,9 @@ namespace Tizen.Multimedia
         {
             Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-            int sampleRate = 0;
-            int channels = 0;
-            int bitRate = 0;
-
-            NativePlayer.GetAudioStreamInfo(Player.Handle, out sampleRate, out channels, out bitRate).
-                ThrowIfFailed("Failed to get audio stream info");
+            NativePlayer.GetAudioStreamInfo(Player.Handle, out var sampleRate,
+                out var channels, out var bitRate).
+                ThrowIfFailed(Player, "Failed to get audio stream info");
 
             return new AudioStreamProperties(sampleRate, channels, bitRate);
         }
@@ -327,11 +318,8 @@ namespace Tizen.Multimedia
         {
             Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-            int fps = 0;
-            int bitRate = 0;
-
-            NativePlayer.GetVideoStreamInfo(Player.Handle, out fps, out bitRate).
-                ThrowIfFailed("Failed to get the video stream info");
+            NativePlayer.GetVideoStreamInfo(Player.Handle, out var fps, out var bitRate).
+                ThrowIfFailed(Player, "Failed to get the video stream info");
 
             return new VideoStreamProperties(fps, bitRate, GetVideoSize());
         }
@@ -340,11 +328,8 @@ namespace Tizen.Multimedia
         {
             Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
 
-            int height = 0;
-            int width = 0;
-
-            NativePlayer.GetVideoSize(Player.Handle, out width, out height).
-                ThrowIfFailed("Failed to get the video size");
+            NativePlayer.GetVideoSize(Player.Handle, out var width, out var height).
+                ThrowIfFailed(Player, "Failed to get the video size");
 
             return new Size(width, height);
         }
@@ -375,7 +360,7 @@ namespace Tizen.Multimedia
             try
             {
                 NativePlayer.GetContentInfo(Player.Handle, key, out ptr).
-                    ThrowIfFailed($"Failed to get the meta data with the key '{ key }'");
+                    ThrowIfFailed(Player, $"Failed to get the meta data with the key '{ key }'");
 
                 return Marshal.PtrToStringAnsi(ptr);
             }