<br /> public partial class PlaybackForm : Form<br /> {<br /> IWavePlayer waveOut;<br /> string fileName = null;<br /> WaveStream mainOutputStream;<br /> WaveChannel32 volumeStream;<br /> int _deviceNum;<br /> int _deviceNum1;<br /> Thread t1;<br /> Thread t2;<br /> public PlaybackForm(int deviceNum,int deviceNum1)<br /> {<br /> InitializeComponent();<br /> _deviceNum = deviceNum;<br /> _deviceNum1 = deviceNum1;<br /> }<br /> private void buttonPlay_Click(object sender, EventArgs e)<br /> {<br /> if (waveOut != null)<br /> {<br /> if (waveOut.PlaybackState == PlaybackState.Playing)<br /> {<br /> return;<br /> }<br /> else if (waveOut.PlaybackState == PlaybackState.Paused)<br /> {<br /> waveOut.Play();<br /> return;<br /> }<br /> }<br /> // we are in a stopped state<br /> // TODO: only re-initialise if necessary<br /> if (String.IsNullOrEmpty(fileName))<br /> {<br /> toolStripButtonOpenFile_Click(sender, e);<br /> }<br /> if (String.IsNullOrEmpty(fileName))<br /> {<br /> return;<br /> }<br /> try<br /> {<br /> CreateWaveOut();<br /> }<br /> catch (Exception driverCreateException)<br /> {<br /> MessageBox.Show(String.Format("{0}", driverCreateException.Message));<br /> return;<br /> }<br /> mainOutputStream = CreateInputStream(fileName);<br /> trackBarPosition.Maximum = (int)mainOutputStream.TotalTime.TotalSeconds;<br /> labelTotalTime.Text = String.Format("{0:00}:{1:00}", (int)mainOutputStream.TotalTime.TotalMinutes,<br /> mainOutputStream.TotalTime.Seconds);<br /> trackBarPosition.TickFrequency = trackBarPosition.Maximum / 30;<br /> try<br /> {<br /> waveOut.Init(mainOutputStream);<br /> }<br /> catch (Exception initException)<br /> {<br /> MessageBox.Show(String.Format("{0}", initException.Message), "Error Initializing Output");<br /> return;<br /> }<br /> // not doing Volume on IWavePlayer any more<br /> volumeStream.Volume = volumeSlider1.Volume;<br /> waveOut.Play();<br /> }<br />
<br /> private void CreateWaveOut()<br /> {<br /> CloseWaveOut();<br /> int latency = (int)comboBoxLatency.SelectedItem;<br /> //if (radioButtonWaveOut.Checked)<br /> {<br /> //WaveCallbackInfo callbackInfo = checkBoxWaveOutWindow.Checked ?<br /> WaveCallbackInfo callbackInfo = WaveCallbackInfo.FunctionCallback();<br /> // WaveCallbackInfo callbackInfo = WaveCallbackInfo.FunctionCallback();<br /> // WaveCallbackInfo.NewWindow(): WaveCallbackInfo.FunctionCallback();<br /> WaveOut outputDevice = new WaveOut(callbackInfo);<br /> outputDevice.DesiredLatency = latency;<br /> outputDevice.DeviceNumber = _deviceNum;<br /> waveOut = outputDevice;<br /> }<br /> }<br />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)