using System.IO;
using System.Threading;
using System.Threading.Tasks;
+using Native = Interop.WavPlayer;
namespace Tizen.Multimedia
{
/// </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="FileFormatException">The format of <paramref name="path"/> is not supported.</exception>
/// <exception cref="ObjectDisposedException"><paramref name="streamPolicy"/> has already been disposed of.</exception>
public static Task StartAsync(string path, AudioStreamPolicy streamPolicy)
{
/// </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>
+ /// <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>
public static Task StartAsync(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.");
+ Native.WavPlayerCompletedCallback cb = (id_, _) => tcs.TrySetResult(true);
- using (RegisterCancellationAction(tcs, cancellationToken, id))
+ using (ObjectKeeper.Get(cb))
{
- await tcs.Task;
+ Native.Start(path, streamPolicy.Handle, cb, IntPtr.Zero, out var id).
+ Validate("Failed to play.");
+
+ using (RegisterCancellationAction(tcs, cancellationToken, id))
+ {
+ await tcs.Task;
+ }
}
}
return cancellationToken.Register(() =>
{
- Interop.WavPlayer.Stop(id).Validate("Failed to cancel");
+ Native.Stop(id).Validate("Failed to cancel");
tcs.TrySetCanceled();
});
}