[A5] audio stream empty on completion of playback


I'm not sure if this is by design or a bug, but I can't seem to play a stream again once it has finished playing the ogg file.

This is roughly my code for playing the ogg files which works well:

1ALLEGRO_AUDIO_STREAM* pMusic = GetMusicResource( nSoundResourceID ); 2 3if( ! pMusic ) 4{ 5 ThrowErrorAndQuit( "Unable to load requested sound resource" ); 6} 7 8al_rewind_audio_stream( pMusic ); 9 10al_attach_audio_stream_to_mixer( pMusic, al_get_default_mixer() );

I can stop and restart this stream/audio track at any time during playback with a call to:

1al_detach_audio_stream( pMusic ); 2 3// call back up to previous code above

.. and that works well too.

However the problem arises when the ogg file finishes playing. When that happens, I can't start playback again using the ALLEGRO_AUDIO_STREAM object, all I get is silence.

Is this by design i.e. stream reaches end of file and is now finished? Is there a way to reset the stream to the start of the file when it reaches the end without destroying and recreating the stream?


Reading up on ALLEGRO_AUDIO_STREAM, it says


you must periodically fill fragments with new audio data. To know when a new fragment is ready to be filled, you can either directly check with al_get_available_audio_stream_fragments, or listen to events from the stream

Maybe this is the cause of it stopping. If you just want to play, stop, and loop an ogg, you can easily do this with ALLEGRO_SAMPLE.


No, if you create the stream yourself that's correct but if you load it from a file Allegro handles the streaming of the chunks and this works. I think it simply purges the stream on reaching the end of the file or there is a bug in Allegro. Either way, when the stream ends I just destroy it and recreate it when the audio needs to be played again.

Thread #612639. Printed from Allegro.cc