How do I play music B after A ends?
amarillion

I have background music consisting of two Ogg files. One is an intro, the other is a loop. So the two should be played like A,B,B,B,... The gap between A and B should be as short as possible.

What is the best way to start audio stream B directly after audio stream A ends? I don't think there is a way to generate an event when an audio stream has finished, and respond to that, right?

I can think of two other ways. One is to carefully set a timer at exactly the moment A is supposed to end, and start playing B at the right moment.

The other is to take control of how the audio buffer is filled. First fill it with data from stream A, until it runs out, then fill it with data from stream B. That's a bit more involved that loading and playing a stream, but it will probably give the most glitchless result.

What do you think is the best approach? Or is there another option?

torhu
RmBeer2

Ideally, you have the music ready and prepared before playing it, so you just stop the above and reproduce the new in 2 lines quickly. Although you could also reproduce the new and then stop the old.

SiegeLord

The other is to take control of how the audio buffer is filled. First fill it with data from stream A, until it runs out, then fill it with data from stream B. That's a bit more involved that loading and playing a stream, but it will probably give the most glitchless result.

This is the only way that will have no playback gaps. We have an issue open to make the loading bit easier: https://github.com/liballeg/allegro5/issues/1046

dthompson

If the oggs aren't absolutely huge - and you're happy with that A,B,B,B pattern - I guess you could do this:

  • Concatenate A and B into a single file with ffmpeg or somesuch

  • Load the file

  • Call al_set_audio_stream_loop_secs, setting start to the original length of A

Thread #618332. Printed from Allegro.cc