So I have found myself in a bit of trouble here. Essentially what I want to do
is automatically play the next chunk in a “play list” by utilizing the
Mix_ChannelFinished callback register to let me know when a sound has finished
playing. This I can do, not a problem. I also want to set the position for
that sound, here is where the issue lies.
Apparantly the Mix_SetPosition uses the same system as the Mix_RegisterEffect
hook system. Mix_RegisterEffect is documented as clearing the effects for a
channel upon that channel completing. So I’m within the completing callback
where we detect that the sound has finished playing. I queue up the next sound
and call Mix_SetPosition and it absolutely does not work. I can set the
position on the channel outside of the Mix_ChannelFinished registered callback
without trouble, swap it around, do whatever. As soon as one sound chunk stops
playing though it resets the position and I have no way of setting it again when
I resume playback.
So my question is, where is it safe for me to call a Mix_RegisterEffect (and
therefore Mix_SetPosition) when using the Mix_ChannelFinished registered
callback to detect a song completing? Any functions I call from
Mix_ChannelFinished obviously also have this limitation of being unable to set
the position.
Here is a code snippet (slightly modified to remove some of the extra features):
Mix_ChannelFinished(AudioSoundHook);
…
void AudioSoundHook(int channel){
static AudioPlayer *player = AudioPlayer::instance();
AudioPlayList *activePlayList = player->getSoundPlayList(channel);
if(activePlayList!=0){
if(activePlayList->advancePlayList()){ //move the playhead
activePlayList->beginPlaying(); //play the next song
}
}
}
void AudioPlayList::beginPlaying(){
AudioPlayer::instance()->playSound(getCurrentSound(), -1, 0, -1, this);
currentChannel = AudioPlayer::instance()->getMostRecentlyUsedChannel();
Mix_SetPosition(currentChannel, currentAngle, currentDistance);
}