Audio play and stop callbacks

Hi there,

I need to to find a better way of doing some operation when a BufferPlayer is playing and when it finishes.

I´m currently doing something like this:

mBufferPlayer->start();
float stopTime = mBufferPlayer->getNumSeconds() + timeline().getCurrentTime();
doStuffAtUpdate = true;
timeline().add([&]{
// do something when audio stops.
doStuffAtUpdate = false;
}, stopTime );


//  ------ at App::update ---
if(doStuffAtUpdate){
//   // recording some visuals with audio
}

The update part works, but I need at least a more reliable way of doing the end callback.

any help is appreciated =)
thanks!

You can check if mBufferPlayer->isEof() is true from the update loop.

In case you’re wondering, there aren’t any callbacks for things like this at present because we don’t want to call out from the audio thread (which is where we find out in BufferPlayerNode's implementation when we’ve reached EOF) for both performance and thread safety reasons, and at current audio::Context doesn’t have any notion of a main-thread update mechanism.

hey,
thanks for the explanation! that totally makes sense =)

but mBufferPlayer->isEof() does not seem to work when mBufferPlayer->setLoopEnabled(true); right?

but anyway, I can make it play again when Eof is true…

thanks again