Search code examples
delphiwinapiaudio

"winmm.dll" won't play certain wav sounds?


Apparently, Windows made some major changes to the audio architecture in Windows Vista.
As I understand it, some "legacy codecs" are not included in Vista and above, but I'm not sure whether this is the cause of the problem.

I am programming in Delphi, and am currently using C:\WINDOWS\System32\winmm.dll from the Windows library and its PlaySound method to play Waveform Audio File Format (WAV) files.
It seems like there are a number of WAV files that winmm.dll cannot play.
Interestingly, Windows Media Player can play the failing sounds, while the Windows Control Panel sound applet cannot. Therefore, I suspect that the failure to play the sounds may be due to a limitation of the library I am using, and is not directly caused by my app.
Still, it causes a bad user experience to have sound files silently fail without any notice to the user that the file is somehow defective and cannot be used.

Is there a different library function I should be using instead to play the WAV sounds with better codec support, which would be able to play these broken files like Windows Media Player can?
If not, is there another function call I could use to test whether a WAV is valid/playable, so I can notify the user that the file's internal format isn't supported?


Solution

  • Window Media Player uses DirectShow which gives you better performance and greater flexibility than PlaySound under MCI. However, it can seem like a lot of effort to play a sound with DirectShow compared to MCI.

    Have a look at the cbAudioPlay component by Carlos Barbosa, as it provides a good example of using DirectShow and contains the associated libs you need.