views:

357

answers:

3

Hi - I'm trying to play mp3 files from my winows mobile application using the newly supported mp3-playing function SndPlaySync ( also tried SndPlayAsync ). I made the simplest program, just attached the function to a WM_KEYDOWN event. ( code attached below ). But stil there is always 0.5-2 seconds of wait before the program plays the mp3. When i simply use PlaySound, and try to play a .wav file, it works instateneously. What can i do?

Code :

This works too slow

case WM_KEYDOWN: 
    PlaySound(c_szMid,NULL,NULL);
    HSOUND hSound;
    HRESULT hr;
    SndOpen(c_szMid, &hSound);
    hr = SndPlayAsync(hSound, 0);
    hr = SndClose(hSound);

And this works fast :

case WM_KEYDOWN: 
    PlaySound(c_szMid,NULL,NULL);

Would be grateful for any ideas!

Thanks!

Dan

+1  A: 

Don't forget that an mp3 file is compressed, whereas a wav isn't.

So the delay might be the time it takes to read the mp3 file into memory and decompress it, which doesn't have to happen with the wav file.

I'm not sure how you'd verify this though.

ChrisF
A: 

Is that code right? Right now you call PlaySound (which is synchronous) followed by the async version. To me that should be playing the sound twice.

Also, if you try using PlaySound with the SND_ASYNC flag what behavior do you see?

ctacke
A: 

I actually added the code where i tried SndPlayAsync, but it worked the same with SndPlaySync.

I actually narrowed down the problem - Even When i try to play wav files using PlaySound(with Sync flag) and using SndPlaySync, SndPlaySync runs twice as slow :(

I'll open a new question about it.

dan