[SDL] playing audio wave file

Bill Kendrick nbs at sonic.net
Tue Sep 12 16:51:25 PDT 2006

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...

If you look here:

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:

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.

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


  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.

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. ;)


More information about the SDL mailing list