/// <summary> /// Run a test of the WaveOut class. /// </summary> /// <param name="showLine">Delegate called to show debug information</param> /* public static void TestProc(MainTest.DisplayLineDelegate showLine) { WaveOut wo = null; try { wo = new WaveOut(); uint numDevices = wo.NumDevices(); if (numDevices < 1) { showLine("FAILURE: No valid sound drivers detected"); return; } showLine(string.Format("{0} device{1} detected:", numDevices, numDevices != 1 ? "s" : "")); for (uint i = 0; i < numDevices; i++) { string prodName = ""; if (Wave.MMSYSERR.NOERROR != wo.GetDeviceName(i, ref prodName)) { showLine(string.Format(" {0}: Failed to get name", i)); } else { showLine(string.Format(" {0}: {1}", i, prodName)); } } String fileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; fileName = Path.GetDirectoryName(fileName); fileName = Path.Combine(fileName, "test.wav"); showLine("Playing sound test.wav"); showLine("Setting stream buffers to 512KB total"); if (Wave.MMSYSERR.NOERROR != wo.Play(fileName, 512*1024, 0xffff, 0xffff)) { showLine("FAILURE: Failed to play sound test.wav"); } uint soundLength = wo.Milliseconds(); int sleepTime = (int)((float)soundLength / 3.0f); showLine(string.Format("Sleeping for {0} ms", sleepTime)); Thread.Sleep(sleepTime); showLine("Pausing for 1 second..."); wo.Pause(); Thread.Sleep(1000); showLine("Resuming..."); wo.Resume(); showLine("Waiting for sound to finish..."); sleepTime = 5; int watchDog = 0; int maxLoops = (int)(wo.Milliseconds() / sleepTime); while(!wo.Done()) { Thread.Sleep(sleepTime); Application.DoEvents(); watchDog++; if (watchDog > maxLoops) { showLine("FAILURE: Failed to detecte end of sound"); return; } } showLine("Done playing sound"); } finally { if (wo != null) wo.Dispose(); } }*/ public static void play( string file ) { WaveOut wo = null; try { wo = new WaveOut(); uint numDevices = wo.NumDevices(); if ( numDevices < 1 ) { MessageBox.Show( "No sound device detected", "Error" ); return; } /*String fileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; fileName = Path.GetDirectoryName(fileName); fileName = Path.Combine( fileName, file ); Path.GetPathRoot( filename );*/ if ( Wave.MMSYSERR.NOERROR != wo.Play(file, 512*1024, 0xffff, 0xffff) ) { MessageBox.Show( "Failed to play the file: " + file, "Error" ); } else { uint soundLength = wo.Milliseconds(); int sleepTime = 5; int watchDog = 0; int maxLoops = (int)(wo.Milliseconds() / sleepTime); while( !wo.Done() ) { Thread.Sleep(sleepTime); Application.DoEvents(); watchDog++; if (watchDog > maxLoops) { return; } } } } finally { if ( wo != null ) wo.Dispose(); } }
public SoundMessageWindow(WaveOut wo) { m_wo = wo; }