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,
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
bool available = false;
Native.EqualizerIsAvailable(Player.Handle, out available).
- ThrowIfFailed("Failed to initialize the AudioEffect");
+ ThrowIfFailed(Player, "Failed to initialize the AudioEffect");
IsAvailable = available;
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);
Player.ValidateNotDisposed();
Native.EqualizerClear(Player.Handle).
- ThrowIfFailed("Failed to clear equalizer effect");
+ ThrowIfFailed(Player, "Failed to clear equalizer effect");
}
/// <summary>
_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;
{
_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;
}
}
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");
}
}
{
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) }.");
}
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");
}
}
}
}
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;
}
}
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;
}
}
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)
_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)
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
{
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");
}
}
}
--- /dev/null
+/*
+ * 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
{
_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()
PlaybackCompleted?.Invoke(this, EventArgs.Empty);
};
NativePlayer.SetCompletedCb(Handle, _playbackCompletedCallback).
- ThrowIfFailed("Failed to set PlaybackCompleted");
+ ThrowIfFailed(this, "Failed to set PlaybackCompleted");
}
private void RegisterPlaybackInterruptedCallback()
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()
};
NativePlayer.SetErrorCb(Handle, _playbackErrorCallback).
- ThrowIfFailed("Failed to set PlaybackError");
+ ThrowIfFailed(this, "Failed to set PlaybackError");
}
#region VideoFrameDecoded event
};
NativePlayer.SetVideoFrameDecodedCb(Handle, _videoFrameDecodedCallback).
- ThrowIfFailed("Failed to register the VideoFrameDecoded");
+ ThrowIfFailed(this, "Failed to register the VideoFrameDecoded");
}
#endregion
{
_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()
_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()
{
Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status));
Log.Debug(PlayerLog.Tag, "audio buffer status : " + status);
+
MediaStreamAudioBufferStatusChanged?.Invoke(this,
new MediaStreamBufferStatusChangedEventArgs(status));
};
{
Debug.Assert(Enum.IsDefined(typeof(MediaStreamBufferStatus), status));
Log.Debug(PlayerLog.Tag, "video buffer status : " + status);
+
MediaStreamVideoBufferStatusChanged?.Invoke(this,
new MediaStreamBufferStatusChangedEventArgs(status));
};
NativePlayer.MediaStreamBufferStatusCallback cb)
{
NativePlayer.SetMediaStreamBufferStatusCb(Handle, streamType, cb).
- ThrowIfFailed("Failed to SetMediaStreamBufferStatus");
+ ThrowIfFailed(this, "Failed to SetMediaStreamBufferStatus");
}
private void RegisterMediaStreamSeekCallback()
private void RegisterMediaStreamSeekCallback(StreamType streamType, NativePlayer.MediaStreamSeekCallback cb)
{
NativePlayer.SetMediaStreamSeekCb(Handle, streamType, cb).
- ThrowIfFailed("Failed to SetMediaStreamSeek");
+ ThrowIfFailed(this, "Failed to SetMediaStreamSeek");
}
}
}
/// <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>
{
get
{
- Log.Info(PlayerLog.Tag, "get cookie : " + _cookie);
return _cookie;
}
set
}
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;
}
{
get
{
- Log.Info(PlayerLog.Tag, "get useragent : " + _userAgent);
return _userAgent;
}
set
}
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;
}
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));
}
}
- private AudioLatencyMode _audioLatencyMode;
-
/// <summary>
/// Gets or sets the audio latency mode.
/// </summary>
{
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>
{
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>
{
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);
}
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");
}
}
{
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
}
NativePlayer.SetVolume(Handle, value, value).
- ThrowIfFailed("Failed to set the volume of the player");
+ ThrowIfFailed(this, "Failed to set the volume of the player");
}
}
}
/// <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);
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);
}
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>
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>
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>
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();
}
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();
}
}
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>
}
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>
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;
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;
}
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);
{
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>
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>
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
}
#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);
}
}
get
{
Native.GetMode(Player.Handle, out var value).
- ThrowIfFailed("Failed to get display mode");
+ ThrowIfFailed(Player, "Failed to get display mode");
return value;
}
ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
Native.SetMode(Player.Handle, value).
- ThrowIfFailed("Failed to set display mode");
+ ThrowIfFailed(Player, "Failed to set display mode");
}
}
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");
}
}
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;
}
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");
}
}
}
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");
}
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
using System;
using System.IO;
using Tizen.Internals.Errors;
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)
case PlayerErrorCode.NotSupportedVideoCodec:
throw new CodecNotSupportedException(CodecKind.Video);
-
}
- throw new InvalidOperationException(msg);
+ return null;
}
}
/// <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;
}
{
_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;
}
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;
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);
{
_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;
}
{
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");
}
}
}
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>
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.
/// <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>
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;
}
try
{
NativePlayer.GetCodecInfo(Player.Handle, out audioPtr, out videoPtr).
- ThrowIfFailed("Failed to get codec info");
+ ThrowIfFailed(Player, "Failed to get codec info");
if (audioInfo)
{
{
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;
{
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);
}
{
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());
}
{
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);
}
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);
}