How to suspend and resume in playing a WAV file

F

fAnSKyer/C# newbie

I am using winmm.dll and I found that I can't just suspend it and
resume it?

What should I do? Any better idea?

Should I use thread? and thread.suspend will work?

Thanks
 
V

VJ

If you are on 2.0 Framework try the soundplayer class. I have not used it,
but I assume you might need to use thread to paly/suspend/resume, or maybe
not. Check it out.

VJ
 
P

Peter Duniho

I am using winmm.dll and I found that I can't just suspend it and
resume it?

What should I do? Any better idea?

Should I use thread? and thread.suspend will work?

It's unlikely that you can simply suspend a thread playing a sound.
First, the thread that calls the API to play the sound is unlikely to have
anything to do with the thread actually playing the sound. Second, the
thread actually playing the sound is likely to be feeding audio samples to
the audio hardware; suspending that thread will just result in the
hardware repeating the same sample over and over.

Fortunately, there is an easier way. :) Look at the AudioVideoPlayback
DirectX component. I am pretty sure that it includes pause/resume
functionality, unlike the basic .NET media SoundPlayer class.

Of course, that said...if you are using winmm.dll (via p/invoke
presumably), the wav/mci API has pause/resume as well, if I recall
correctly. IMHO using the AVP component is easier, since it doesn't
require p/invoke in your application, but you ought to be able to pause
and resume audio playback using the same playback mechanism you're using
now.

Pete
 
M

MBR

It's been a while, but if you're using the MCI interface win WINMM (either
the mciSendString version or the command version) you should be able to
pause without a problem.

For example, using mciSendString, if you send:
"play c:\foo.wav alias a"
then you can follow up with:
"pause a"
and
"resume a"

Of course you can also do:
"set a timeformat milliseconds"
"play a from 0 to 23323"
etc...

Hope that helps -
thanks,
m
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top