Playing audio wave file

Hi,
I playing a wav successfully; but I’m wondering: how do I play the file
in a loop? (I’d like when file reach the end, automatically jump to
begin and restart). Is it possible?
Thanks

Let’s assume you’re using SDL_mixer, since that’s what most people do…

If you look here:
http://www.libsdl.org/cgi/docwiki.cgi/Mix_5fPlayChannel

It says:
int Mix_PlayChannel (int channel, Mix_Chunk *chunk, int loops);

The chunk will be looped loops times. (The total number of times
played will be loops+1.)

See also:
http://jcatki.no-ip.org/SDL_mixer/SDL_mixer.html#SEC24

Depending on how you’re coding your app, you may also want to use:

int Mix_Playing(int channel)
Tells you if channel is playing, or not.
http://jcatki.no-ip.org/SDL_mixer/SDL_mixer.html#SEC34

to simply play the sound again, when you noticed it has stopped,

or:

void Mix_ChannelFinished(void (*channel_finished)(int channel))
When channel playback is halted, then the specified channel_finished
function is called. The channel parameter will contain the channel
number that has finished.
http://jcatki.no-ip.org/SDL_mixer/SDL_mixer.html#SEC33

to have SDL_mixer call a function immediately when your sound has stopped.
Note that you cannot actually restart the sound within the callback.
You’ll want to set a global flag, or fire off a user event.

It helps to look at the docs. :wink:

-bill!On Wed, Sep 13, 2006 at 12:55:41AM +0200, Michi wrote:

Hi,
I playing a wav successfully; but I’m wondering: how do I play the file
in a loop? (I’d like when file reach the end, automatically jump to
begin and restart). Is it possible?

no I’m not using this way…can I do that with this code?
http://www.libsdl.org/intro.it/usingsound.html
thanksOn 13/09/2006 1.51, Bill Kendrick wrote:

On Wed, Sep 13, 2006 at 12:55:41AM +0200, Michi wrote:

Hi,
I playing a wav successfully; but I’m wondering: how do I play the file
in a loop? (I’d like when file reach the end, automatically jump to
begin and restart). Is it possible?

Let’s assume you’re using SDL_mixer, since that’s what most people do…

no I’m not using this way…can I do that with this code?
http://www.libsdl.org/intro.it/usingsound.html

Take a look at loopwave.c in the test subdirectory of the SDL source code.

See ya!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

I’m working for it! But I download dsl 1.2.11 (befire I used 1.2.7); and
a runtime error occured; it can’t find SDL_strcy in dynamic link
sdl.dll; after I put .dll in my folfer app and work!!!
in my old configuration I linked my app to …\SDL-1.2.11\lib and
sdl.dll wasn’t necessary in my application folder…and it worked! why?
thanksOn 14/09/2006 9.00, Sam Lantinga wrote:

no I’m not using this way…can I do that with this code?
http://www.libsdl.org/intro.it/usingsound.html

Take a look at loopwave.c in the test subdirectory of the SDL source code.

See ya!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl