Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] audio stream empty on completion of playback

This thread is locked; no one can reply to it. rss feed Print
[A5] audio stream empty on completion of playback
Ionising
Member #14,522
August 2012

Hey,

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:

#SelectExpand
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:

#SelectExpand
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?

ph03nix
Member #15,028
April 2013
avatar

Reading up on ALLEGRO_AUDIO_STREAM, it says

Quote:

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.

Ionising
Member #14,522
August 2012

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.

Go to: