<PropertyGroup>
<TizenVersion>1.0.5</TizenVersion>
- <ElmSharpVersion>1.2.0</ElmSharpVersion>
+ <ElmSharpVersion>1.2.1</ElmSharpVersion>
<ApplicationsVersion>1.5.8</ApplicationsVersion>
<SystemInfoVersion>1.0.4</SystemInfoVersion>
</PropertyGroup>
internal static partial class TonePlayer
{
[DllImport(Libraries.TonePlayer, EntryPoint = "tone_player_start_new")]
- internal static extern int Start(ToneType tone, IntPtr streamInfoHandle, int durationMs, out int playerId);
+ internal static extern TonePlayerError Start(ToneType tone, IntPtr streamInfoHandle,
+ int durationMs, out int id);
[DllImport(Libraries.TonePlayer, EntryPoint = "tone_player_stop")]
- internal static extern int Stop(int PlayerId);
+ internal static extern TonePlayerError Stop(int id);
}
}
using System;
using System.Runtime.InteropServices;
+using Tizen.Multimedia;
internal static partial class Interop
{
internal delegate void WavPlayerCompletedCallback(int playerId, IntPtr userData);
[DllImport(Libraries.WavPlayer, EntryPoint = "wav_player_start_new")]
- internal static extern int WavPlayerStart(string filePath, IntPtr streamInfoHandle, WavPlayerCompletedCallback completedCallback,
- IntPtr userData, out int playerId);
+ internal static extern WavPlayerError Start(string filePath, IntPtr streamInfoHandle,
+ WavPlayerCompletedCallback completedCallback, IntPtr userData, out int id);
[DllImport(Libraries.WavPlayer, EntryPoint = "wav_player_stop")]
- internal static extern int WavPlayerStop(int PlayerId);
+ internal static extern WavPlayerError Stop(int id);
}
}
+
<Import Project="../build/build.props" />
<PropertyGroup>
- <Version>1.0.0</Version>
+ <Version>1.0.1</Version>
<Description>Provides the Multimedia AudioIO API for Tizen .NET</Description>
</PropertyGroup>
*/
using System;
-using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace Tizen.Multimedia
{
- static internal class TonePlayerLog
- {
- internal const string LogTag = "Tizen.Multimedia.TonePlayer";
- }
-
/// <summary>
- /// The TonePlayer class allows you to play and stop playing the tone. To play a particular
- /// type of tone <see cref="Tizen.Multimedia.ToneType"/>,
- /// use <see cref="Tizen.Multimedia.TonePlayer.StartAsync"/>.
+ /// Provides the ability to play a tone.
/// </summary>
public static class TonePlayer
{
/// <summary>
/// Plays a tone, asynchronously.
/// </summary>
- /// <param name="tone">The tone type to play.</param>
- /// <param name="streamPolicy">The Audiostream policy object.</param>
- /// <param name="durationMs">The tone duration in milliseconds. -1 indicates an infinite duration.</param>
+ /// <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.</exception>
+ public static Task StartAsync(ToneType tone, AudioStreamPolicy streamPolicy,
+ int durationMilliseconds)
+ {
+ return StartAsync(tone, streamPolicy, durationMilliseconds, CancellationToken.None);
+ }
+
+ /// <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>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
- /// <exception cref="ArgumentNullException">In case of null parameters</exception>
- /// <exception cref="ArgumentOutOfRangeException">In case of play duration less than -1.</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of tone type not supported.</exception>
- public static async Task StartAsync(ToneType tone, AudioStreamPolicy streamPolicy, int durationMs, CancellationToken cancellationToken = default(CancellationToken))
+ /// <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.</exception>
+ public static Task StartAsync(ToneType tone, AudioStreamPolicy streamPolicy,
+ int durationMilliseconds, CancellationToken cancellationToken)
{
- if (durationMs < -1)
+ if (durationMilliseconds < -1)
{
- throw new ArgumentOutOfRangeException(nameof(durationMs));
+ 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);
}
- if (Enum.IsDefined(typeof(ToneType), tone) == false)
+ return StartAsyncCore(tone, streamPolicy, durationMilliseconds, cancellationToken);
+ }
+
+ private static async Task StartAsyncCore(ToneType tone, AudioStreamPolicy streamPolicy,
+ int durationMilliseconds, CancellationToken cancellationToken)
+ {
+
+ var tcs = new TaskCompletionSource<bool>();
+
+ Interop.TonePlayer.Start(tone, streamPolicy.Handle, durationMilliseconds, out var id).
+ Validate("Failed to play tone.");
+
+ using (RegisterCancellationAction(tcs, cancellationToken, id))
{
- throw new ArgumentException("Invalid ToneType provided : " + tone);
+ await WaitForDuration(tcs, cancellationToken, durationMilliseconds);
+
+ await tcs.Task;
}
+ }
- int id;
- var task = new TaskCompletionSource<int>();
- int ret = Interop.TonePlayer.Start(tone, streamPolicy.Handle, durationMs, out id);
- if (ret != (int)TonePlayerError.None)
+ private static async Task WaitForDuration(TaskCompletionSource<bool> tcs,
+ CancellationToken cancellationToken, int durationMilliseconds)
+ {
+ if (durationMilliseconds == -1)
{
- Log.Error(TonePlayerLog.LogTag, "Error Occured with error code: " + (TonePlayerError)ret);
- throw TonePlayerErrorFactory.CreateException(ret, "Failed to play tone.");
+ return;
}
- if (cancellationToken != CancellationToken.None)
+ try
{
- cancellationToken.Register((playerId) =>
- {
- int resultCancel = Interop.TonePlayer.Stop((int)playerId);
- if ((TonePlayerError)resultCancel != TonePlayerError.None)
- {
- Log.Error(TonePlayerLog.LogTag, "Failed to stop tone Player with error code: " + (TonePlayerError)resultCancel);
- }
- task.TrySetCanceled();
- }, id);
+ await Task.Delay(durationMilliseconds, cancellationToken);
+ tcs.TrySetResult(true);
}
+ catch (TaskCanceledException)
+ {
+ }
+ }
- if (durationMs != -1)
+ private static IDisposable RegisterCancellationAction(TaskCompletionSource<bool> tcs,
+ CancellationToken cancellationToken, int id)
+ {
+ if (cancellationToken.CanBeCanceled == false)
{
- Task delayTask = Task.Delay(durationMs, cancellationToken);
- await delayTask;
- if (delayTask.IsCompleted)
- {
- task.TrySetResult(id);
- }
+ return null;
}
- await task.Task;
+
+ return cancellationToken.Register(() =>
+ {
+ Interop.TonePlayer.Stop(id).Validate("Failed to cancel");
+ tcs.TrySetCanceled();
+ });
}
}
}
-/*
+/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
TypeNotSupported = TizenErrorTonePlayer | 0x01
}
- internal static class TonePlayerErrorFactory
+ internal static class TonePlayerErrorExtensions
{
- internal static Exception CreateException(int errorCode, string errorMessage)
+ internal static void Validate(this TonePlayerError error, string message)
{
- TonePlayerError err = (TonePlayerError)errorCode;
- Exception exp;
- if (string.IsNullOrEmpty(errorMessage))
+ if (error == TonePlayerError.None)
{
- errorMessage = err.ToString();
+ return;
}
- switch ((TonePlayerError)errorCode)
+ switch (error)
{
case TonePlayerError.InvalidParameter:
- {
- exp = new ArgumentException(errorMessage + "Invalid parameters provided");
- break;
- }
+ throw new ArgumentException(message);
case TonePlayerError.TypeNotSupported:
- {
- exp = new NotSupportedException(errorMessage + "Not Supported");
- break;
- }
+ throw new NotSupportedException(message);
case TonePlayerError.InvalidOperation:
- {
- exp = new InvalidOperationException(errorMessage + "Invalid Operation");
- break;
- }
+ throw new InvalidOperationException(message);
+
default:
- {
- exp = new InvalidOperationException(errorMessage);
- break;
- }
+ throw new InvalidOperationException(message);
+
}
- return exp;
}
}
}
* limitations under the License.
*/
-using System;
-
namespace Tizen.Multimedia
{
/// <summary>
/// </summary>
DtmfS,
/// <summary>
- /// Predefined DTMF sharP (#).
+ /// Predefined DTMF sharp (#).
/// </summary>
DtmfP,
/// <summary>
*/
using System;
-using System.Runtime.InteropServices;
+using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Tizen.Multimedia
{
- static internal class WavPlayerLog
- {
- internal const string LogTag = "Tizen.Multimedia.WavPlayer";
- }
-
/// <summary>
- /// The WavPlayer class allows you to simply play and stop a wav file. To play a certain
- /// wav file, call <see cref="Tizen.Multimedia.WavPlayer.StartAsync"/> with
- /// a path to the .wav file.
+ /// Provides the ability to play a wav file.
/// </summary>
public static class WavPlayer
{
/// <summary>
- /// Plays a WAV file with the stream information of AudioManager, asynchronously.
+ /// Plays a wav file based on the specified <see cref="AudioStreamPolicy"/>.
/// </summary>
- /// <param name="inputFilePath">The file path to play.</param>
- /// <param name="streamPolicy">The Audiostream policy object.</param>
- /// <param name="cancellationToken">The cancellation token which can be used to stop the Wav Player.</param>
- /// <returns>The WAV player ID.</returns>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
- /// <exception cref="ArgumentNullException">In case of null parameters</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of format not supported.</exception>
- public static async Task StartAsync(string inputFilePath, AudioStreamPolicy streamPolicy, CancellationToken cancellationToken = default(CancellationToken))
+ /// <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=""/> is not supported.</exception>
+ /// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed of.</exception>
+ public static Task StartAsync(string path, AudioStreamPolicy streamPolicy)
{
- int id;
- var task = new TaskCompletionSource<int>();
+ return StartAsync(path, streamPolicy, CancellationToken.None);
+ }
- if (String.IsNullOrEmpty(inputFilePath))
+ /// <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=""/> is not supported.</exception>
+ /// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed.</exception>
+ public static Task StartAsync(string path, AudioStreamPolicy streamPolicy,
+ CancellationToken cancellationToken)
+ {
+ if (path == null)
{
- throw new ArgumentNullException(nameof(inputFilePath));
+ throw new ArgumentNullException(nameof(path));
}
if (streamPolicy == null)
throw new ArgumentNullException(nameof(streamPolicy));
}
- Interop.WavPlayer.WavPlayerCompletedCallback _playerCompletedCallback = (int playerId, IntPtr userData) =>
+ if (File.Exists(path) == false)
{
- task.TrySetResult(playerId);
- };
- GCHandle callbackHandle = GCHandle.Alloc(_playerCompletedCallback);
+ throw new FileNotFoundException("File does not exists.", path);
+ }
- int ret = Interop.WavPlayer.WavPlayerStart(inputFilePath, streamPolicy.Handle, _playerCompletedCallback, IntPtr.Zero, out id);
- if (ret != (int)WavPlayerError.None)
+ return cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
+ StartAsyncCore(path, streamPolicy, cancellationToken);
+ }
+
+ private static async Task StartAsyncCore(string path, AudioStreamPolicy streamPolicy,
+ CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource<bool>();
+
+ Interop.WavPlayer.WavPlayerCompletedCallback cb = (id_, _) => tcs.TrySetResult(true);
+
+ Interop.WavPlayer.Start(path, streamPolicy.Handle, cb, IntPtr.Zero, out var id).
+ Validate("Failed to play.");
+
+ using (RegisterCancellationAction(tcs, cancellationToken, id))
{
- Log.Error(WavPlayerLog.LogTag, "Error Occured with error code: " + (WavPlayerError)ret);
- task.TrySetException(WavPlayerErrorFactory.CreateException(ret, "Failed to play Wav file."));
+ await tcs.Task;
}
+ }
- if (cancellationToken != CancellationToken.None)
+ private static IDisposable RegisterCancellationAction(TaskCompletionSource<bool> tcs,
+ CancellationToken cancellationToken, int id)
+ {
+ if (cancellationToken.CanBeCanceled == false)
{
- cancellationToken.Register((playerId) =>
- {
- int resultCancel = Interop.WavPlayer.WavPlayerStop((int)playerId);
- if ((WavPlayerError)resultCancel != WavPlayerError.None)
- {
- Log.Error(WavPlayerLog.LogTag, "Failed to stop Wav Player with error code: " + (WavPlayerError)resultCancel);
- }
- task.TrySetCanceled();
- }, id);
+ return null;
}
- await task.Task;
- callbackHandle.Free();
+ return cancellationToken.Register(() =>
+ {
+ Interop.WavPlayer.Stop(id).Validate("Failed to cancel");
+ tcs.TrySetCanceled();
+ });
}
}
}
--- /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 Tizen.Internals.Errors;
+
+namespace Tizen.Multimedia
+{
+ internal enum WavPlayerError
+ {
+ None = ErrorCode.None,
+ InvalidParameter = ErrorCode.InvalidParameter,
+ InvalidOperation = ErrorCode.InvalidOperation,
+ TizenErrorWavPlayer = -0x01990000,
+ FormatNotSupported = TizenErrorWavPlayer | 0x01,
+ NotSupportedType = TizenErrorWavPlayer | 0x02
+ }
+
+ internal static class WavPlayerErrorExtensions
+ {
+ internal static void Validate(this WavPlayerError error, string message)
+ {
+ if (error == WavPlayerError.None)
+ {
+ return;
+ }
+
+ switch (error)
+ {
+ case WavPlayerError.InvalidParameter:
+ throw new ArgumentException(message);
+
+ case WavPlayerError.FormatNotSupported:
+
+ case WavPlayerError.NotSupportedType:
+ throw new NotSupportedException(message);
+
+ case WavPlayerError.InvalidOperation:
+ throw new InvalidOperationException(message);
+ }
+ }
+ }
+
+}
+++ /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 Tizen.Internals.Errors;
-
-namespace Tizen.Multimedia
-{
- internal enum WavPlayerError
- {
- None = ErrorCode.None,
- InvalidParameter = ErrorCode.InvalidParameter,
- InvalidOperation = ErrorCode.InvalidOperation,
- TizenErrorWavPlayer = -0x01990000,
- FormatNotSupported = TizenErrorWavPlayer | 0x01,
- NotSupportedType = TizenErrorWavPlayer | 0x02
- }
-
- internal static class WavPlayerErrorFactory
- {
- internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null)
- {
- WavPlayerError err = (WavPlayerError)errorCode;
- if (string.IsNullOrEmpty(errorMessage))
- {
- errorMessage = err.ToString();
- }
-
- switch ((WavPlayerError)errorCode)
- {
- case WavPlayerError.InvalidParameter:
- throw new ArgumentException(errorMessage, paramName);
-
- case WavPlayerError.FormatNotSupported:
- case WavPlayerError.NotSupportedType:
- throw new NotSupportedException(errorMessage);
-
- case WavPlayerError.InvalidOperation:
- throw new InvalidOperationException(errorMessage);
- }
- }
-
- internal static Exception CreateException(int errorCode, string errorMessage)
- {
- WavPlayerError err = (WavPlayerError)errorCode;
- Exception exp;
- if (string.IsNullOrEmpty(errorMessage))
- {
- errorMessage = err.ToString();
- }
-
- switch ((WavPlayerError)errorCode)
- {
- case WavPlayerError.InvalidParameter:
- {
- exp = new ArgumentException(errorMessage + "Invalid parameters provided");
- break;
- }
-
- case WavPlayerError.FormatNotSupported:
- case WavPlayerError.NotSupportedType:
- {
- exp = new NotSupportedException(errorMessage + "Not Supported");
- break;
- }
-
- case WavPlayerError.InvalidOperation:
- {
- exp = new InvalidOperationException(errorMessage + "Invalid Operation");
- break;
- }
- default:
- {
- exp = new InvalidOperationException(errorMessage);
- break;
- }
- }
- return exp;
- }
- }
-}
private void ReplaceDisplay(Display newDisplay)
{
- if (_display != null)
- {
- _display.Owner = null;
- }
+ _display?.SetOwner(null);
_display = newDisplay;
- if (_display != null)
- {
- _display.Owner = this;
- }
+ _display?.SetOwner(this);
}
/// <summary>
{
ValidateState(CameraState.Created);
- if (value != null && value.Owner != null)
+ if (value?.Owner != null)
{
if (ReferenceEquals(this, value.Owner))
{
return;
}
- else
- {
- throw new ArgumentException("The display has already been assigned to another.");
- }
+
+ throw new ArgumentException("The display has already been assigned to another.");
}
+
CameraErrorFactory.ThrowIfError(SetDisplay(value), "Failed to set the camera display");
ReplaceDisplay(value);
Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
}
- public int Count{ get; }
+ /// <summary>
+ /// Get the number of items.
+ /// </summary>
+ public int Count { get; }
/// <summary>
/// Get the band level range of the bands in dB.
/// </summary>
public class BufferingProgressChangedEventArgs : EventArgs
{
+ /// <summary>
+ /// Initializes a new instance of the BufferingProgressChangedEventArgs class.
+ /// </summary>
+ /// <param name="percent">The value indicating the buffering percentage.</param>
public BufferingProgressChangedEventArgs(int percent)
{
Percent = percent;
namespace Tizen.Multimedia
{
- //TODO we need a better name.
/// <summary>
/// Represents data for a video frame captured.
/// </summary>
_callbackRegistered = true;
}
+ /// <summary>
+ /// Gets the native handle of the player.
+ /// </summary>
+ /// <value>An IntPtr that contains the native handle of the player.</value>
+ /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
public IntPtr Handle
{
get
{
ValidateNotDisposed();
- //TODO is this needed?
if (IsPreparing())
{
return PlayerState.Preparing;
private PlayerErrorCode SetDisplay(Display display)
{
- Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
if (display == null)
{
Log.Info(PlayerLog.Tag, "set display to none");
private void ReplaceDisplay(Display newDisplay)
{
- if (_display != null)
- {
- _display.Owner = null;
- }
+ _display?.SetOwner(null);
_display = newDisplay;
- if (_display != null)
- {
- _display.Owner = this;
- }
+ _display?.SetOwner(this);
}
/// <summary>
}
set
{
- Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
ValidatePlayerState(PlayerState.Idle);
- if (value != null && value.Owner != null)
+ if (value?.Owner != null)
{
if (ReferenceEquals(this, value.Owner))
{
return;
}
- else
- {
- throw new ArgumentException("The display has already been assigned to another.");
- }
- }
+ throw new ArgumentException("The display has already been assigned to another.");
+ }
SetDisplay(value).ThrowIfFailed("Failed to set the display to the player");
ReplaceDisplay(value);
- Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
}
}
#region Dispose support
private bool _disposed;
+ /// <summary>
+ /// Releases all resources used by the current instance.
+ /// </summary>
public void Dispose()
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
}
/// <summary>
- /// Get Streaming download Progress.
+ /// Gets the streaming download Progress.
/// </summary>
+ /// <returns>The <see cref="DownloadProgress"/> containing current download progress.</returns>
/// <remarks>The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="InvalidOperationException">
/// The player is not streaming.\n
/// <summary>
/// Sets the offset for the subtitle.
/// </summary>
+ /// <param name="offset">The value indicating a desired offset in milliseconds.</param>
/// <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">
/// <summary>
/// Prepares the media player for playback, asynchronously.
/// </summary>
+ /// <returns>A task that represents the asynchronous prepare operation.</returns>
/// <remarks>To prepare the player, the player must be in the <see cref="PlayerState.Idle"/> state,
/// and a source must be set.</remarks>
/// <exception cref="InvalidOperationException">No source is set.</exception>
_source = null;
}
- //TODO remarks needs to be updated. see the native reference.
/// <summary>
/// Starts or resumes playback.
/// </summary>
/// <remarks>
/// The player must be in the <see cref="PlayerState.Ready"/> or <see cref="PlayerState.Paused"/> state.
- /// It has no effect if the player is already in the <see cref="PlayerState.Playing"/> state.
+ /// It has no effect if the player is already in the <see cref="PlayerState.Playing"/> state.\n
+ /// \n
+ /// Sound can be mixed with other sounds if you don't control the stream focus using <see cref="ApplyAudioStreamPolicy"/>.
/// </remarks>
/// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
/// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
/// <seealso cref="Stop"/>
/// <seealso cref="Pause"/>
/// <seealso cref="PlaybackCompleted"/>
+ /// <seealso cref="ApplyAudioStreamPolicy"/>
public virtual void Start()
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
/// <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>
/// <summary>
/// Gets or sets the value indicating whether the display is visible.
/// </summary>
- /// <value></value>
+ /// <value>true if the display is visible; otherwise false.</value>
/// <exception cref="InvalidOperationException">
/// The display is not assigned.\n
/// -or-\n
/// <summary>
/// Sets the roi(region of interest).
/// </summary>
+ /// <param name="roi">The region.</param>
/// <remarks>
/// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
/// </remarks>
/// <seealso cref="PlayerErrorOccurredEventArgs"/>
public enum PlayerError
{
+ /// <summary>
+ /// File does not exists.
+ /// </summary>
NoSuchFile = ErrorCode.NoSuchFile,
+
+ /// <summary>
+ /// Internal error.
+ /// </summary>
InternalError = ErrorCode.InvalidOperation,
+
+ /// <summary>
+ /// No space.
+ /// </summary>
NoSpaceOnDevice = PlayerErrorCode.NoSpaceOnDevice,
+
+ //TODO must be removed.
+ /// <summary>
+ /// Not supported.
+ /// </summary>
FeatureNotSupported = ErrorCode.NotSupported,
+
+ //TODO must be removed.
+ /// <summary>
+ /// Permission denined.
+ /// </summary>
PermissionDenied = ErrorCode.PermissionDenied,
+
+ /// <summary>
+ /// Not enough buffer.
+ /// </summary>
BufferSpace = ErrorCode.BufferSpace,
+
+ /// <summary>
+ /// <see cref="Player.SetPlayPositionAsync(int, bool)/> failed.
+ /// </summary>
SeekFailed = PlayerErrorCode.SeekFailed,
+
+ /// <summary>
+ /// Invalid state.
+ /// </summary>
InvalidState = PlayerErrorCode.InvalidState,
+
+ /// <summary>
+ /// Not supported file.
+ /// </summary>
NotSupportedFile = PlayerErrorCode.NotSupportedFile,
+
+ /// <summary>
+ /// Invalid uri.
+ /// </summary>
InvalidUri = PlayerErrorCode.InvalidUri,
+
+ //TODO must be removed.
+ /// <summary>
+ /// Sound policy error.
+ /// </summary>
SoundPolicy = PlayerErrorCode.SoundPolicyError,
+
+ /// <summary>
+ /// Connection to service failed.
+ /// </summary>
ConnectionFailed = PlayerErrorCode.ConnectionFailed,
+
+ // TODO must be removed.
+ /// <summary>
+ /// Capture failed.
+ /// </summary>
VideoCaptureFailed = PlayerErrorCode.VideoCaptureFailed,
+
+ // TODO must be removed.
+ /// <summary>
+ /// DRM expired.
+ /// </summary>
DrmExpired = PlayerErrorCode.DrmExpired,
+
+ // TODO must be removed.
+ /// <summary>
+ /// No license of DRM.
+ /// </summary>
DrmNoLicense = PlayerErrorCode.DrmNoLicense,
+
+ // TODO must be removed.
+ /// <summary>
+ /// Not used.
+ /// </summary>
DrmFutureUse = PlayerErrorCode.DrmFutureUse,
+
+ /// <summary>
+ /// Not permitted DRM.
+ /// </summary>
DrmNotPermitted = PlayerErrorCode.DrmNotPermitted,
+
+ // TODO must be removed.
+ /// <summary>
+ /// Not enough resource.
+ /// </summary>
ResourceLimit = PlayerErrorCode.ResourceLimit,
+
+ /// <summary>
+ /// Service disconnected.
+ /// </summary>
ServiceDisconnected = PlayerErrorCode.ServiceDisconnected,
+
+ /// <summary>
+ /// Not supported subtitle file.
+ /// </summary>
SubtitleNotSupported = PlayerErrorCode.NotSupportedSubtitle,
}
/// <summary>
/// Initialize a new instance of the AudioStreamProperties struct with the specified sample rate, channels and bit rate.
/// </summary>
+ /// <param name="sampleRate">The sample rate of the stream.</param>
+ /// <param name="channels">The number of channels of the stream.</param>
+ /// <param name="bitRate">The bit rate of the stream.</param>
public AudioStreamProperties(int sampleRate, int channels, int bitRate)
{
SampleRate = sampleRate;
/// <summary>
/// Initialize a new instance of the VideoStreamProperties struct with the specified fps, bit rate and size.
/// </summary>
+ /// <param name="fps">The fps of the stream.</param>
+ /// <param name="bitRate">The bit rate of the stream.</param>
+ /// <param name="size">The size of the stream.</param>
public VideoStreamProperties(int fps, int bitRate, Size size)
{
Fps = fps;
/// <summary>
/// Initialize a new instance of the VideoStreamProperties struct with the specified fps, bit rate, width and height.
/// </summary>
+ /// <param name="fps">The fps of the stream.</param>
+ /// <param name="bitRate">The bit rate of the stream.</param>
+ /// <param name="width">The width of the stream.</param>
+ /// <param name="height">The height of the stream.</param>
public VideoStreamProperties(int fps, int bitRate, int width, int height)
{
Fps = fps;
/// <summary>
/// Retrieves the album art of the stream or null if there is no album art data.
/// </summary>
+ /// <returns>Raw byte array if album art exists; otherwise null.</returns>
/// <remarks>The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed.</exception>
/// <exception cref="InvalidOperationException">The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.</exception>
/// <summary>
/// Retrieves the codec name of audio or null if there is no audio.
/// </summary>
+ /// <returns>A string that represents codec name.</returns>
public string GetAudioCodec()
{
return GetCodecInfo(true);
/// <summary>
/// Retrieves the codec name of video or null if there is no video.
/// </summary>
+ /// <returns>A string that represents codec name.</returns>
public string GetVideoCodec()
{
return GetCodecInfo(false);
/// <summary>
/// Gets the duration.
/// </summary>
+ /// <returns>The duration of the stream.</returns>
/// <remarks>The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed.</exception>
/// <exception cref="InvalidOperationException">The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.</exception>
/// <summary>
/// Gets the properties of audio.
/// </summary>
+ /// <returns>A <see cref="AudioStreamProperties"/> that contains audio stream information.</returns>
/// <remarks>The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed.</exception>
/// <exception cref="InvalidOperationException">The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.</exception>
/// <summary>
/// Gets the properties of video.
/// </summary>
+ /// <returns>A <see cref="VideoStreamProperties"/> that contains video stream information.</returns>
/// <remarks>The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed.</exception>
/// <exception cref="InvalidOperationException">The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.</exception>
/// <summary>
/// Gets the metadata with the specified key.
/// </summary>
+ /// <returns>A string that represents the value of the specified key.</returns>
/// <param name="key">The key to query.</param>
/// <remarks>The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed.</exception>
private void ReplaceDisplay(Display newDisplay)
{
- if (_display != null)
- {
- _display.Owner = null;
- }
+ _display?.SetOwner(null);
_display = newDisplay;
- if (_display != null)
- {
- _display.Owner = this;
- }
+ _display?.SetOwner(this);
}
/// <summary>
/// <summary>
/// Sets the color-space to decode into. The default is <see cref="ColorSpace.Rgba8888"/>.
/// </summary>
+ /// <param name="colorSpace">The value indicating color-space to decode into.</param>
/// <exception cref="ArgumentException"><paramref name="colorSpace"/> is invalid.</exception>
/// <exception cref="NotSupportedException"><paramref name="colorSpace"/> is not supported by the decoder.</exception>
/// <seealso cref="ImageUtil.GetSupportedColorspace(ImageFormat)"/>
#region IDisposable Support
private bool _disposed = false;
+ /// <summary>
+ /// Releases the unmanaged resources used by the ImageDecoder.
+ /// </summary>
+ /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
}
}
- ~ImageDecoder()
- {
- Dispose(false);
- }
-
+ /// <summary>
+ /// Releases all resources used by the ImageDecoder.
+ /// </summary>
public void Dispose()
{
Dispose(true);
- GC.SuppressFinalize(this);
}
#endregion
}
}
/// <summary>
- /// Sets the colorspace of the output image.
+ /// Sets the color-space of the output image.
/// </summary>
- /// <param name="colorSpace">The target colorspace.</param>
+ /// <param name="colorSpace">The target color-space.</param>
/// <exception cref="ArgumentException"><paramref name="colorSpace"/> is invalid.</exception>
/// <exception cref="NotSupportedException"><paramref name="colorSpace"/> is not supported by the encoder.</exception>
/// <seealso cref="ImageUtil.GetSupportedColorspace(ImageFormat)"/>
#region IDisposable Support
private bool _disposed = false;
+ /// <summary>
+ /// Releases the unmanaged resources used by the ImageEncoder.
+ /// </summary>
+ /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
}
}
+ /// <summary>
+ /// Releases all resources used by the ImageEncoder.
+ /// </summary>
public void Dispose()
{
Dispose(true);
/// <summary>
/// Initialize a new instance of the <see cref="JpegEncoder"/> class with initial quality value.
/// </summary>
+ /// <param name="quality">The quality for JPEG image encoding; from 1(lowest quality) to 100(highest quality).</param>
/// <remarks><see cref="ImageEncoder.OutputFormat"/> will be the <see cref="ImageFormat.Jpeg"/>.</remarks>
/// <exception cref="ArgumentOutOfRangeException">
- /// <paramref name="quality"/> is less than 0.\n
+ /// <paramref name="quality"/> is less than or equal to 0.\n
/// - or -\n
/// <paramref name="quality"/> is greater than 100.
/// </exception>
/// <summary>
/// Gets or sets the quality of the encoded image.
/// </summary>
- /// <value>The quality of the output image. The default is 75.</value>
+ /// <value>
+ /// The quality of the output image. The default is 75.\n
+ /// Valid value is from 1(lowest quality) to 100(highest quality).
+ /// </value>
/// <exception cref="ArgumentOutOfRangeException">
- /// <paramref name="value"/> is less than 0.\n
+ /// <paramref name="value"/> is less than or equal to 0.\n
/// - or -\n
/// <paramref name="value"/> is greater than 100.
/// </exception>
get { return _quality ?? DefaultQuality; }
set
{
- if (value < 0 || value > 100)
+ if (value <= 0 || value > 100)
{
throw new ArgumentOutOfRangeException(nameof(Quality), value,
"Valid range is from 1 to 100, inclusive.");
/// <summary>
/// Encodes a Graphics Interchange Format (GIF) image from multiple raw image buffers to a specified <see cref="Stream"/>.
/// </summary>
- /// <param name="inputBuffer">The image buffer to encode.</param>
+ /// <param name="frames">The image frames to encode.</param>
/// <param name="outStream">The stream that the image is encoded to.</param>
/// <returns>A task that represents the asynchronous encoding operation.</returns>
/// <exception cref="ArgumentNullException">
#region IDisposable Support
private bool _disposed = false;
+ /// <summary>
+ /// Releases the unmanaged resources used by the ImageTransformer.
+ /// </summary>
+ /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
}
}
+ /// <summary>
+ /// Releases all resources used by the ImageTransformer.
+ /// </summary>
public void Dispose()
{
Dispose(true);
/// <summary>
/// Retrieves supported colorspaces for a <see cref="ImageFormat"/> that represents formats for <see cref="ImageEncoder"/> and <see cref="ImageDecoder"/>.
/// </summary>
- /// <param name="format"><see cref="ImageFormat"/>.</param>
+ /// <returns>An IEnumerable of <see="ColorSpace"/> representing the supported color-spaces.</returns>
+ /// <param name="format">The <see cref="ImageFormat"/>.</param>
/// <exception cref="ArgumentException"><paramref name="format"/> is invalid.</exception>
public static IEnumerable<ColorSpace> GetSupportedColorSpaces(ImageFormat format)
{
/// <summary>
/// Calculates the size of the image buffer for the specified resolution and color-space.
/// </summary>
- /// <param name="size">Resolution of the image.</param>
+ /// <param name="resolution">The resolution of the image.</param>
/// <param name="colorSpace"><see cref="ColorSpace"/> of the image.</param>
- /// <returns>Buffer size.</returns>
+ /// <returns>The buffer size.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width of <paramref name="resolution"/> is less than or equal to zero.\n
/// - or -\n
private DisplayType Type { get; }
- internal object Owner
+ private object _owner;
+
+ internal object Owner => _owner;
+
+ internal void SetOwner(object newOwner)
{
- get;
- set;
+ if (_owner != null && newOwner != null)
+ {
+ throw new ArgumentException("The display has already been assigned to another.");
+ }
+
+ _owner = newOwner;
}
internal ErrorType ApplyTo<ErrorType>(IDisplayable<ErrorType> target)