private void BackgroundPlayer_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { object[] arguments = e.Argument as object[]; WaveStream WaveFloat = (WaveStream)arguments[0]; int LeftPos = Conversions.ToInteger(arguments[1]); int RightPos = Conversions.ToInteger(arguments[2]); var bytes = new byte[RightPos - LeftPos + 1]; WaveFloat.Position = LeftPos; WaveFloat.Read(bytes, 0, RightPos - LeftPos); WaveFloat = new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat); // WaveFloat.PadWithZeroes = False using (var output = new WaveOutEvent()) { output.Init(WaveFloat); output.Play(); while (output.PlaybackState == PlaybackState.Playing & !BackgroundPlayer.CancellationPending) { Thread.Sleep(45); BackgroundPlayer.ReportProgress((int)(output.GetPosition() / (WaveFloat.WaveFormat.BitsPerSample / 8d))); } } }
private void BackgroundPlayer_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { WaveStream WaveFloat = (e.Argument as object[])[0] as WaveStream; int LeftPos = (int)(e.Argument as object[])[1]; int RightPos = (int)(e.Argument as object[])[2]; byte[] bytes = new byte[(RightPos - LeftPos) + 1]; WaveFloat.Position = LeftPos; WaveFloat.Read(bytes, 0, (RightPos - LeftPos)); WaveFloat = new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat); //WaveFloat.PadWithZeroes = False using (var output = new WaveOutEvent()) { output.Init(WaveFloat); output.Play(); while (output.PlaybackState == PlaybackState.Playing & !BackgroundPlayer.CancellationPending) { Thread.Sleep(45); BackgroundPlayer.ReportProgress((int)output.GetPosition() / (WaveFloat.WaveFormat.BitsPerSample / 8)); } } }