{
}
+ internal PlayerHandle(IntPtr rawHandle) : this()
+ {
+ handle = rawHandle;
+ }
+
public override bool IsInvalid => handle == IntPtr.Zero;
protected override bool ReleaseHandle()
*/
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 Action<int, string> _errorHandler;
- 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)
+ internal void NotifyError(int errorCode, string message)
{
- if (errorHandler == null)
- {
- throw new ArgumentNullException(nameof(errorHandler));
- }
-
- lock (_errorHandlerLock)
- {
- if (_errorHandlers == null)
- {
- _errorHandlers = new List<Action<Player, int, string>>();
- }
-
- _errorHandlers.Add(errorHandler);
- }
+ _errorHandler?.Invoke(errorCode, message);
}
/// <summary>
/// </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);
- }
- }
- }
-
- /// <summary>
- /// This method supports the product infrastructure and is not intended to be used directly from application code.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
protected static Exception GetException(int errorCode, string message) =>
((PlayerErrorCode)errorCode).GetException(message);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+using static Interop;
using System;
-using System.Threading.Tasks;
-using System.Runtime.InteropServices;
+using System.ComponentModel;
using System.Diagnostics;
-using System.IO;
-using System.Threading;
-using static Interop;
namespace Tizen.Multimedia
{
internal event EventHandler<MediaStreamSeekingOccurredEventArgs> MediaStreamVideoSeekingOccurred;
private NativePlayer.MediaStreamSeekCallback _mediaStreamVideoSeekCallback;
- private bool _callbackRegistered;
-
private void RegisterEvents()
{
- if (_callbackRegistered)
- {
- return;
- }
RegisterSubtitleUpdatedCallback();
RegisterErrorOccurredCallback();
RegisterPlaybackInterruptedCallback();
RegisterMediaStreamBufferStatusCallback();
RegisterMediaStreamSeekCallback();
RegisterPlaybackCompletedCallback();
-
- _callbackRegistered = true;
}
private void RegisterSubtitleUpdatedCallback()
ThrowIfFailed(this, "Failed to set PlaybackError");
}
+ /// <summary>
+ /// Raises the <see cref="ErrorOccurred"/> event.
+ /// </summary>
+ /// <param name="e">
+ /// An <see cref="PlayerErrorOccurredEventArgs"/> that contains the event data.
+ /// </param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void OnErrorOccurred(PlayerErrorOccurredEventArgs e)
+ {
+ ErrorOccurred?.Invoke(this, e);
+ }
+
#region VideoFrameDecoded event
private EventHandler<VideoFrameDecodedEventArgs> _videoFrameDecoded;
#region Display methods
+ private PlayerDisplaySettings _displaySettings;
+
/// <summary>
/// Gets the display settings.
/// </summary>
/// <value>A <see cref="PlayerDisplaySettings"/> that specifies the display settings.</value>
/// <since_tizen> 3 </since_tizen>
- public PlayerDisplaySettings DisplaySettings { get; }
+ public PlayerDisplaySettings DisplaySettings => _displaySettings;
private Display _display;
throw new ArgumentException("The display has already been assigned to another.");
}
+ SetDisplay(value).ThrowIfFailed(this, "Failed to configure display of the player");
+
ReplaceDisplay(value);
}
}
}
}
- private readonly AudioEffect _audioEffect;
+ private AudioEffect _audioEffect;
/// <summary>
/// Gets the audio effect.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+using static Interop;
using System;
-using System.Threading.Tasks;
-using System.Runtime.InteropServices;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
+using System.Runtime.InteropServices;
using System.Threading;
-using static Interop;
-using System.ComponentModel;
+using System.Threading.Tasks;
namespace Tizen.Multimedia
{
/// </remarks>
public partial class Player : IDisposable, IDisplayable<PlayerErrorCode>
{
- private PlayerHandle _handle;
+ private readonly PlayerHandle _handle;
/// <summary>
/// Initializes a new instance of the <see cref="Player"/> class.
Debug.Assert(_handle != null);
+ Initialize();
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Player"/> class with a native handle.
+ /// The class takes care of the life cycle of the handle.
+ /// Thus, it should not be closed/destroyed in another location.
+ /// </summary>
+ /// <remarks>
+ /// This supports the product infrastructure and is not intended to be used directly from application code.
+ /// </remarks>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected Player(IntPtr handle, Action<int, string> errorHandler)
+ {
+ // This constructor is to support TV product player.
+ // Be careful with 'handle'. It must be wrapped in safe handle, first.
+ _handle = handle != IntPtr.Zero ? new PlayerHandle(handle) :
+ throw new ArgumentException("Handle is invalid.", nameof(handle));
+
+ _errorHandler = errorHandler;
+ }
+
+ private bool _initialized;
+
+ /// <summary>
+ /// This supports the product infrastructure and is not intended to be used directly from application code.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void Initialize()
+ {
+ if (_initialized)
+ {
+ throw new InvalidOperationException("It has already been initialized.");
+ }
+
if (Features.IsSupported(PlayerFeatures.AudioEffect))
{
_audioEffect = new AudioEffect(this);
RegisterVideoFrameDecodedCallback();
}
- DisplaySettings = PlayerDisplaySettings.Create(this);
+ RegisterEvents();
+
+ _displaySettings = PlayerDisplaySettings.Create(this);
+
+ _initialized = true;
}
internal void ValidatePlayerState(params PlayerState[] desiredStates)
Dispose(true);
}
- private void Dispose(bool disposing)
+ /// <summary>
+ /// Releases the unmanaged resources used by the <see cref="Player"/>.
+ /// </summary>
+ /// <param name="disposing">
+ /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+ /// </param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
/// <since_tizen> 3 </since_tizen>
protected virtual void OnPreparing()
{
- RegisterEvents();
}
/// <summary>
ValidatePlayerState(PlayerState.Idle);
- SetDisplay(_display).ThrowIfFailed(this, "Failed to configure display of the player");
-
OnPreparing();
var completionSource = new TaskCompletionSource<bool>();
private MediaSource _source;
/// <summary>
+ /// Determines whether MediaSource has set.
+ /// This supports the product infrastructure and is not intended to be used directly from application code.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected bool HasSource => _source != null;
+
+ /// <summary>
/// Sets a media source for the player.
/// </summary>
/// <param name="source">A <see cref="MediaSource"/> that specifies the source for playback.</param>
return Interlocked.CompareExchange(ref _isPreparing, 1, 1) == 1;
}
- private void SetPreparing()
+ /// <summary>
+ /// This supports the product infrastructure and is not intended to be used directly from application code.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void SetPreparing()
{
Interlocked.Exchange(ref _isPreparing, 1);
}
- private void ClearPreparing()
+ /// <summary>
+ /// This supports the product infrastructure and is not intended to be used directly from application code.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected void ClearPreparing()
{
Interlocked.Exchange(ref _isPreparing, 0);
}
if (ex == null)
{
// Notify only when it can't be handled.
- Player.NotifyError(player, (int)err, message);
+ player?.NotifyError((int)err, message);
throw new InvalidOperationException($"Unknown error : {err.ToString()}");
}