コード例 #1
0
ファイル: Player.cs プロジェクト: mk5004lee/TizenFX
        /// <summary>
        /// Captures a video frame, asynchronously.
        /// </summary>
        /// <returns>A task that represents the asynchronous capture operation.</returns>
        /// <feature>http://tizen.org/feature/multimedia.raw_video</feature>
        /// <remarks>The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
        /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
        /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
        /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
        /// <since_tizen> 3 </since_tizen>
        public async Task <CapturedFrame> CaptureVideoAsync()
        {
            ValidationUtil.ValidateFeatureSupported(PlayerFeatures.RawVideo);

            ValidatePlayerState(PlayerState.Playing, PlayerState.Paused);

            TaskCompletionSource <CapturedFrame> t = new TaskCompletionSource <CapturedFrame>();

            NativePlayer.VideoCaptureCallback cb = (data, width, height, size, _) =>
            {
                Debug.Assert(size <= int.MaxValue);

                byte[] buf = new byte[size];
                Marshal.Copy(data, buf, 0, (int)size);

                t.TrySetResult(new CapturedFrame(buf, width, height));
            };

            using (var cbKeeper = ObjectKeeper.Get(cb))
            {
                NativePlayer.CaptureVideo(Handle, cb)
                .ThrowIfFailed(this, "Failed to capture the video");

                return(await t.Task);
            }
        }
コード例 #2
0
ファイル: Radio.cs プロジェクト: younghajung/TizenFX
        private async Task <int> SeekAsync(
            Func <RadioHandle, Native.SeekCompletedCallback, IntPtr, RadioError> func)
        {
            ValidateRadioState(RadioState.Playing);

            var tcs = new TaskCompletionSource <int>();

            Native.SeekCompletedCallback callback =
                (currentFrequency, _) => tcs.TrySetResult(currentFrequency);

            using (ObjectKeeper.Get(callback))
            {
                func(Handle, callback, IntPtr.Zero).ThrowIfFailed("Failed to seek");
                return(await tcs.Task);
            }
        }
コード例 #3
0
        private static async Task StartAsyncCore(string path, AudioStreamPolicy streamPolicy,
                                                 CancellationToken cancellationToken)
        {
            var tcs = new TaskCompletionSource <bool>();

            Native.WavPlayerCompletedCallback cb = (id_, _) => tcs.TrySetResult(true);

            using (ObjectKeeper.Get(cb))
            {
                Native.Start(path, streamPolicy.Handle, cb, IntPtr.Zero, out var id).
                Validate("Failed to play.");

                using (RegisterCancellationAction(tcs, cancellationToken, id))
                {
                    await tcs.Task;
                }
            }
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: junqingma/TizenFX
        private async Task SetPlayPosition(long position, bool accurate, bool nanoseconds)
        {
            var taskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);

            bool immediateResult = _source is MediaStreamSource;

            NativePlayer.SeekCompletedCallback cb = _ => taskCompletionSource.TrySetResult(true);

            using (var cbKeeper = ObjectKeeper.Get(cb))
            {
                NativeSetPlayPosition(position, accurate, nanoseconds, immediateResult ? null : cb);

                if (immediateResult)
                {
                    taskCompletionSource.TrySetResult(true);
                }
                await taskCompletionSource.Task;
            }
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: mk5004lee/TizenFX
        /// <summary>
        /// Sets the seek position for playback, asynchronously.
        /// </summary>
        /// <param name="position">The value indicating a desired position in milliseconds.</param>
        /// <param name="accurate">The value indicating whether the operation performs with accuracy.</param>
        /// <remarks>
        ///     <para>The player must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/>,
        ///     or <see cref="PlayerState.Paused"/> state.</para>
        ///     <para>If the <paramref name="accurate"/> is true, the play position will be adjusted as the specified <paramref name="position"/> value,
        ///     but this might be considerably slow. If false, the play position will be a nearest keyframe position.</para>
        ///     </remarks>
        /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
        /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The specified position is not valid.</exception>
        /// <seealso cref="GetPlayPosition"/>
        /// <since_tizen> 3 </since_tizen>
        public async Task SetPlayPositionAsync(int position, bool accurate)
        {
            ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            var taskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);

            bool immediateResult = _source is MediaStreamSource;

            NativePlayer.SeekCompletedCallback cb = _ => taskCompletionSource.TrySetResult(true);

            using (var cbKeeper = ObjectKeeper.Get(cb))
            {
                SetPlayPosition(position, accurate, cb);
                if (immediateResult)
                {
                    taskCompletionSource.TrySetResult(true);
                }

                await taskCompletionSource.Task;
            }
        }