Beispiel #1
0
		/// <summary>
		/// Begins playing the audio stroed in the supplied stream
		/// </summary>
		/// <returns>The async.</returns>
		/// <param name="stream">Stream.</param>
		/// <param name="token">Token.</param>
		public async Task PlayAsync (Stream stream, IProgress<TimeSpan> monitor, CancellationToken token)
		{
			// Cancel the previous 'PlayAsync' call and then set up the cancellation for this invocation
			var cancellation = CancellationTokenSource.CreateLinkedTokenSource (token);
			previousCancellation.Cancel ();
			previousCancellation = cancellation;

			await previousPlayAsync.WaitOrCanceled ();
			token.ThrowIfCancellationRequested ();

			Reset ();
			fileStream = new AudioFileStream (AudioFileType.MP3);
			fileStream.PacketDecoded += AudioPacketDecoded;
			fileStream.PropertyFound += AudioPropertyFound;

			previousPlayAsync = BeginPlayingAsync (stream, monitor, cancellation);
			await previousPlayAsync.WaitOrCanceled ();
			// If the original token is cancelled we should throw a cancelled exception.
			token.ThrowIfCancellationRequested ();
		}