Ejemplo n.º 1
0
        /// <summary>
        /// Apply the audio stream policy.
        /// </summary>
        /// <remarks>
        /// The recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
        /// </remarks>
        /// <param name="policy">The policy to apply.</param>
        /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception>
        /// <exception cref="InvalidOperationException">
        ///     The recorder is not in the valid state.<br/>
        ///     -or-<br/>
        ///     <paramref name="policy"/> is not supported for the recorder.<br/>
        ///     -or-<br/>
        ///     An internal error occurred.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The recorder already has been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="policy"/> already has been disposed of.
        /// </exception>
        /// <since_tizen> 4 </since_tizen>
        public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            ValidateState(RecorderState.Idle, RecorderState.Ready);

            Native.SetAudioStreamPolicy(Handle, policy.Handle).ThrowIfError("Failed to apply the audio stream policy.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the sound stream information to the audio input.
        /// </summary>
        /// <param name="streamPolicy">The <see cref="AudioStreamPolicy"/> to apply for the AudioCapture.</param>
        /// <exception cref="ArgumentNullException"><paramref name="streamPolicy"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="streamPolicy"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     The AudioCaptureBase has already been disposed of.
        /// </exception>
        /// <exception cref="NotSupportedException"><paramref name="streamPolicy"/> is not supported.</exception>
        /// <exception cref="ArgumentException">Not able to retrieve information from <paramref name="streamPolicy"/>.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void ApplyStreamPolicy(AudioStreamPolicy streamPolicy)
        {
            if (streamPolicy == null)
            {
                throw new ArgumentNullException(nameof(streamPolicy));
            }

            ValidateNotDisposed();

            AudioIOUtil.ThrowIfError(AudioInput.SetStreamInfo(_handle, streamPolicy.Handle));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Applies the audio stream policy.
        /// </summary>
        /// <param name="policy">The <see cref="AudioStreamPolicy"/> to apply.</param>
        /// <remarks>
        /// The player must be in the <see cref="PlayerState.Idle"/> state.<br/>
        /// <br/>
        /// <see cref="Player"/> does not support all <see cref="AudioStreamType"/>.<br/>
        /// Supported types are <see cref="AudioStreamType.Media"/>, <see cref="AudioStreamType.System"/>,
        /// <see cref="AudioStreamType.Alarm"/>, <see cref="AudioStreamType.Notification"/>,
        /// <see cref="AudioStreamType.Emergency"/>, <see cref="AudioStreamType.VoiceInformation"/>,
        /// <see cref="AudioStreamType.RingtoneVoip"/> and <see cref="AudioStreamType.MediaExternalOnly"/>.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        ///     The player has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="policy"/> has already been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception>
        /// <exception cref="NotSupportedException">
        ///     <see cref="AudioStreamType"/> of <paramref name="policy"/> is not supported by <see cref="Player"/>.
        /// </exception>
        /// <seealso cref="AudioStreamPolicy"/>
        /// <since_tizen> 3 </since_tizen>
        public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            ValidatePlayerState(PlayerState.Idle);

            NativePlayer.SetAudioPolicyInfo(Handle, policy.Handle).
            ThrowIfFailed("Failed to set the audio stream policy to the player");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the sound stream information to the audio input.
        /// </summary>
        /// <param name="streamPolicy">The <see cref="AudioStreamPolicy"/> to apply for the AudioCapture.</param>
        /// <exception cref="ArgumentNullException"><paramref name="streamPolicy"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="streamPolicy"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     The AudioCaptureBase has already been disposed of.
        /// </exception>
        /// <exception cref="NotSupportedException"><paramref name="streamPolicy"/> is not supported.</exception>
        /// <exception cref="ArgumentException">Not able to retrieve information from <paramref name="streamPolicy"/>.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void ApplyStreamPolicy(AudioStreamPolicy streamPolicy)
        {
            if (streamPolicy == null)
            {
                throw new ArgumentNullException(nameof(streamPolicy));
            }

            ValidateNotDisposed();

            AudioInput.SetStreamInfo(_handle, streamPolicy.Handle)
            .ThrowIfFailed("Failed to apply stream policy.");
        }
Ejemplo n.º 5
0
        private static async Task StartAsyncCore(ToneType tone, AudioStreamPolicy streamPolicy,
                                                 int durationMilliseconds, CancellationToken cancellationToken)
        {
            var tcs = new TaskCompletionSource <bool>();

            Native.Start(tone, streamPolicy.Handle, durationMilliseconds, out var id).
            Validate("Failed to play tone.");

            using (RegisterCancellationAction(tcs, cancellationToken, id))
            {
                await WaitForDuration(tcs, cancellationToken, durationMilliseconds);

                await tcs.Task;
            }
        }
Ejemplo n.º 6
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;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Applies the audio stream policy.
        /// </summary>
        /// <param name="policy">The <see cref="AudioStreamPolicy"/> to apply.</param>
        /// <remarks>
        /// The player must be in the <see cref="PlayerState.Idle"/> state.<br/>
        /// <br/>
        /// <see cref="Player"/> does not support all <see cref="AudioStreamType"/>.<br/>
        /// Supported types are <see cref="AudioStreamType.Media"/>, <see cref="AudioStreamType.System"/>,
        /// <see cref="AudioStreamType.Alarm"/>, <see cref="AudioStreamType.Notification"/>,
        /// <see cref="AudioStreamType.Emergency"/>, <see cref="AudioStreamType.VoiceInformation"/>,
        /// <see cref="AudioStreamType.RingtoneVoip"/> and <see cref="AudioStreamType.MediaExternalOnly"/>.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        ///     The player has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="policy"/> has already been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception>
        /// <exception cref="NotSupportedException">
        ///     The required feature is not supported.<br/>
        ///     -or-<br/>
        ///     <see cref="AudioStreamType"/> of <paramref name="policy"/> is not supported on the current platform.
        /// </exception>
        /// <seealso cref="AudioStreamPolicy"/>
        /// <feature>http://tizen.org/feature/multimedia.player.stream_info</feature>
        /// <since_tizen> 3 </since_tizen>
        public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)
        {
            ValidationUtil.ValidateFeatureSupported("http://tizen.org/feature/multimedia.player.stream_info");

            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            ValidatePlayerState(PlayerState.Idle);

            var ret = NativePlayer.SetAudioPolicyInfo(Handle, policy.Handle);

            if (ret == PlayerErrorCode.InvalidArgument)
            {
                throw new NotSupportedException("The specified policy is not supported on the current system.");
            }

            ret.ThrowIfFailed(this, "Failed to set the audio stream policy to the player");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Plays a wav file based on the specified <see cref="AudioStreamPolicy"/>.
        /// </summary>
        /// <returns>A task that represents the asynchronous operation.</returns>
        /// <param name="path">A file path to play.</param>
        /// <param name="streamPolicy">A <see cref="AudioStreamPolicy"/>.</param>
        /// <param name="cancellationToken">A cancellation token which can be used to stop.</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="path"/> is null.
        ///     <para>-or-</para>
        ///     <paramref name="streamPolicy"/> is null.
        /// </exception>
        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
        /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exists.</exception>
        /// <exception cref="FileFormatException">The format of <paramref name="path"/> is not supported.</exception>
        /// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed of.</exception>
        /// <since_tizen> 3 </since_tizen>
        public static Task StartAsync(string path, AudioStreamPolicy streamPolicy,
                                      CancellationToken cancellationToken)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (streamPolicy == null)
            {
                throw new ArgumentNullException(nameof(streamPolicy));
            }

            if (File.Exists(path) == false)
            {
                throw new FileNotFoundException("File does not exists.", path);
            }

            return(cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
                   StartAsyncCore(path, streamPolicy, cancellationToken));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Plays a tone, asynchronously.
        /// </summary>
        /// <param name="tone">A <see cref="ToneType"/> to play.</param>
        /// <param name="streamPolicy">A <see cref="AudioStreamPolicy"/>.</param>
        /// <param name="durationMilliseconds">The tone duration in milliseconds. -1 indicates an infinite duration.</param>
        /// <param name="cancellationToken">The cancellation token which can be used to stop playing the tone.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentException"><paramref name="tone"/> is invalid.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="streamPolicy"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="durationMilliseconds"/> is less than -1.</exception>
        /// <exception cref="InvalidOperationException">Any invalid operations occurred.</exception>
        /// <exception cref="NotSupportedException"><paramref name="tone"/> is not a supported type.</exception>
        /// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed of.</exception>
        /// <since_tizen> 3 </since_tizen>
        public static Task StartAsync(ToneType tone, AudioStreamPolicy streamPolicy,
                                      int durationMilliseconds, CancellationToken cancellationToken)
        {
            if (durationMilliseconds < -1)
            {
                throw new ArgumentOutOfRangeException(nameof(durationMilliseconds), durationMilliseconds,
                                                      $"{nameof(durationMilliseconds)} can't be less than -1.");
            }

            if (streamPolicy == null)
            {
                throw new ArgumentNullException(nameof(streamPolicy));
            }

            ValidationUtil.ValidateEnum(typeof(ToneType), tone, nameof(tone));

            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled(cancellationToken));
            }

            return(StartAsyncCore(tone, streamPolicy, durationMilliseconds, cancellationToken));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Plays a tone, asynchronously.
 /// </summary>
 /// <param name="tone">A <see cref="ToneType"/> to play.</param>
 /// <param name="streamPolicy">A <see cref="AudioStreamPolicy"/>.</param>
 /// <param name="durationMilliseconds">The tone duration in milliseconds. -1 indicates an infinite duration.</param>
 /// <returns>A task that represents the asynchronous operation.</returns>
 /// <exception cref="ArgumentException"><paramref name="tone"/> is invalid.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="streamPolicy"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="durationMilliseconds"/> is less than -1.</exception>
 /// <exception cref="InvalidOperationException">Any invalid operations occurred.</exception>
 /// <exception cref="NotSupportedException"><paramref name="tone"/> is not a supported type.</exception>
 /// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed of.</exception>
 /// <since_tizen> 3 </since_tizen>
 public static Task StartAsync(ToneType tone, AudioStreamPolicy streamPolicy,
                               int durationMilliseconds)
 {
     return(StartAsync(tone, streamPolicy, durationMilliseconds, CancellationToken.None));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Plays a wav file based on the specified <see cref="AudioStreamPolicy"/>.
 /// </summary>
 /// <returns>A task that represents the asynchronous operation.</returns>
 /// <param name="path">A file path to play.</param>
 /// <param name="streamPolicy">A <see cref="AudioStreamPolicy"/>.</param>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="path"/> is null.
 ///     <para>-or-</para>
 ///     <paramref name="streamPolicy"/> is null.
 /// </exception>
 /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
 /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exists.</exception>
 /// <exception cref="FileFormatException">The format of <paramref name="path"/> is not supported.</exception>
 /// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed of.</exception>
 /// <since_tizen> 3 </since_tizen>
 public static Task StartAsync(string path, AudioStreamPolicy streamPolicy)
 {
     return(StartAsync(path, streamPolicy, CancellationToken.None));
 }