Search code examples
c#windows-cemotorola-emdk

Windows CE - The wave header is corrupt


I search all the Internet and yet didn't find a solution to my problem. I want just to play a sound from a resource, but it always, always gives me The wave header is corrupt. I saw several workarounds to solve this, like to set the Stream.Position to 0, nullify the Stream and after reload the sound, but it yet doesn't work. The piece of my code is this:

case TipoEvento.Erro:
    SoundPlayer player = new SoundPlayer(); 
    Stream sound = new MemoryStream(Properties.Resources.cow_single_cow_mooing);
    sound.Position = 0;
    player.Stream = null;
    player.Stream = sound;
    player.Play();
    break;

First i instantiate a SoundPlayer, then I read the bytes of the mp3 file I want to play, that is in Properties.Resources. Then I modify some attributes and finally go play. When I try to play, then the exception is throwed. How in the world can I play a sound in Windows CE? (.NET Framework 2.5, I have no File.ReadAllBytes()).


Solution

  • Note: SoundPlayer only plays WAV files....not MP3.

    Either convert your MP3 to a WAV file (which would result in a much bigger file)....or use the Windows Media Player control, or convert the MP3 data (using NAudio), etc.