Mix_PlayChannelTimed
Name
Mix_PlayChannelTimed -- Play an audio chunk on a specific channel for a certain amount of time.
Synopsis
#include "SDL_mixer.h" int Mix_PlayChannelTimed(int which, Mix_Chunk *chunk, int loops, int ticks)
Description
Mix_PlayChannelTimed If the sample is long enough and has enough loops then the sample will stop after ticks milliseconds. Otherwise this function is the same as Mix_PlayChannel
Parameters
channel
- Channel to play on, or -1 for the first free unreserved channel.
chunk
- Sample to play.
loops
- Number of loops, -1 is infinite loops.
- Passing one here plays the sample twice (1 loop).
ticks
- Millisecond limit to play sample, at most.
- If not enough loops or the sample chunk is not long enough, then the sample may stop before this timeout occurs.
- -1 means play forever.
Return Value
Returns the channel the sample is played on. On any errors, -1 is returned.
Example
// play sample on first free unreserved channel
// play it for half a second
// Mix_Chunk *sample; //previously loaded
if(Mix_PlayChannelTimed(-1, sample, -1 , 500)==-1) {
printf("Mix_PlayChannel: %s\n",Mix_GetError());
// may be critical error, or maybe just no channels were free.
// you could allocated another channel in that case...
}
See Also
Mix_PlayChannel, Mix_FadeInChannelTimed, Mix_FadeOutChannel, Mix_ReserveChannels
