Audio and MIDI library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

849 B

Play an Audio File from a Console application

To play a file from a console application, we will use AudioFileReader as a simple way of opening our audio file, and WaveOutEvent as the output device.

We simply need to pass the audioFile into the outputDevice with the Init method, and then call Play.

Since Play only means "start playing" and isn't blocking, we can wait in a loop until playback finishes.

Afterwards, we need to Dispose our audioFile and outputDevice, which in this example we do by virtue of putting them inside using blocks.

using(var audioFile = new AudioFileReader(audioFile))
using(var outputDevice = new WaveOutEvent())
{
    outputDevice.Init(audioFile);
    outputDevice.Play();
    while (outputDevice.PlaybackState == PlaybackState.Playing)
    {
        Thread.Sleep(1000);
    }
}