X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FTizen.Multimedia.MediaPlayer%2FPlayer%2FPlayer.cs;h=ac1b78f64a1aa2ad67a94eb0becc0bbd52a861a3;hb=2b5864e3b7d3aac4d4d6f768bfdff518a16d388d;hp=10f939ace453ef6aac878ac262e8fbe1d08bea63;hpb=d38463ecb8859124318ce7539f0cc3d6f18317d9;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git
diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
index 10f939a..ac1b78f 100644
--- a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
+++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
@@ -346,6 +346,75 @@ namespace Tizen.Multimedia
}
///
+ /// Prepares the cancellable media player for playback, asynchronously.
+ ///
+ /// The cancellation token to cancel preparing.
+ ///
+ /// A task that represents the asynchronous prepare operation.
+ /// To prepare the player, the player must be in the state,
+ /// and a source must be set.
+ /// The state must be to cancel preparing.
+ /// When preparing is cancelled, a state will be changed to from .
+ /// The player has already been disposed of.
+ ///
+ /// Operation failed; internal error.
+ /// -or-
+ /// The player is not in the valid state.
+ ///
+ ///
+ ///
+ /// 6
+ public virtual async Task PrepareAsync(CancellationToken cancellationToken)
+ {
+ ValidateNotDisposed();
+
+ var taskCompletionSource = new TaskCompletionSource();
+
+ if (_source == null)
+ {
+ throw new InvalidOperationException("No source is set.");
+ }
+
+ ValidatePlayerState(PlayerState.Idle);
+
+ OnPreparing();
+
+ SetPreparing();
+
+ // register a callback to handle cancellation token anytime it occurs
+ cancellationToken.Register(() =>
+ {
+ ValidatePlayerState(PlayerState.Preparing);
+
+ // a user can get the state before finally block is called.
+ ClearPreparing();
+
+ Log.Warn(PlayerLog.Tag, $"preparing will be cancelled.");
+ NativePlayer.Unprepare(Handle).ThrowIfFailed(this, "Failed to unprepare the player");
+
+ taskCompletionSource.TrySetCanceled();
+ });
+
+ _prepareCallback = _ =>
+ {
+ Log.Warn(PlayerLog.Tag, $"prepared callback is called.");
+ taskCompletionSource.TrySetResult(true);
+ };
+
+ try
+ {
+ NativePlayer.PrepareAsync(Handle, _prepareCallback, IntPtr.Zero).
+ ThrowIfFailed(this, "Failed to prepare the player");
+
+ await taskCompletionSource.Task.ConfigureAwait(false);
+ }
+ finally
+ {
+ ClearPreparing();
+ }
+ }
+
+ ///
/// Unprepares the player.
///
///
@@ -889,7 +958,7 @@ namespace Tizen.Multimedia
///
/// Enable to decode an audio data for exporting PCM from a data.
///
- /// The media format handle about required audio PCM specification.
+ /// The media format handle required to audio PCM specification.
/// The format has to include ,
/// and .
/// If the format is NULL, the original PCM format or platform default PCM format will be applied.
@@ -915,8 +984,6 @@ namespace Tizen.Multimedia
ValidatePlayerState(PlayerState.Idle);
ValidationUtil.ValidateEnum(typeof(PlayerAudioExtractOption), option, nameof(option));
- IntPtr formatHandle = IntPtr.Zero;
-
_audioFrameDecodedCallback = (IntPtr packetHandle, IntPtr userData) =>
{
var handler = AudioDataDecoded;
@@ -932,10 +999,8 @@ namespace Tizen.Multimedia
}
};
- formatHandle = format.AsNativeHandle();
-
- NativePlayer.SetAudioFrameDecodedCb(Handle, formatHandle, option, _audioFrameDecodedCallback, IntPtr.Zero).
- ThrowIfFailed(this, "Failed to register the _audioFrameDecoded");
+ NativePlayer.SetAudioFrameDecodedCb(Handle, format == null ? IntPtr.Zero : format.AsNativeHandle(), option,
+ _audioFrameDecodedCallback, IntPtr.Zero).ThrowIfFailed(this, "Failed to register the _audioFrameDecoded");
}
///