I've been confronted to a situation. I'm writing a Windows app in C# .NET. I want to play multiple .wav files one after another and do that continuously.
is there a class that could allow that ? otherwise, how would I implement it ?
I tried using MCI and it works, using the notify flag and interception of the MM_MCINOTIFY message but it's rather messy and complicates my code.
If the list of files is fixed, then just make a playlist and pass it to an instance of MediaPlayer. media player accepts playlist in either .m3u format or .wvx format.
But if you need to choose the order of files dynamically, one if the easiest way is to use PlaySound(). You hand it individual filenames, or pointers to wave data in memory (you would have to marshal that to unmanaged memory). Either dedicate a thread to the sound, and have it just call
PlaySound
in a loop, or useSND_ASYNC
.Note that it is possible just by looking at the header of a wave file to know how long it will take to play a file with a high degree of accuracy.
Both of these methods will allow you to mix files of different bit depth and sample rate. But they will also both put a slight amount of silence between the files. If you need the transitions between the files to be seamless then you will need to either find a 3rd party audio engine, or roll your own.
Or, you can write a multiple-wave-file file stream reader (in C++, not C# it has to be unmanaged code). And use it instead of the default .wav file reader to play the files in MediaPlayer.