private void playStoped(object sender, StoppedEventArgs e) { player.Stop(); player.Dispose(); volumeStream.Close(); Console.WriteLine("a"); }
public async Task PlayMp3FromUrl(string url, bool withTimer = true) { AudioUrl = url; Stream ms = new MemoryStream(); Stream stream = WebRequest.Create(url).GetResponse().GetResponseStream(); byte[] buffer = new byte[32768]; int read; Application.UseWaitCursor = true; await Task.Run(() => { while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } }); Application.UseWaitCursor = false; stream.Close(); ms.Position = 0; WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(ms))); WaveOut.Init(blockAlignedStream); WaveOut.Play(); if (withTimer) { StopAudioTimer.Start(); } while (WaveOut.PlaybackState == PlaybackState.Playing) { await Task.Delay(100); } blockAlignedStream.Close(); ms.Close(); }