Playing long music
You might think that playing music will mean detecting whether the sound is complete and restarting it. This is probably true for the browser's implementation, but fortunately, you don't have to do it. The Web Audio API already has a flag on the AudioBufferSourceNode
loop that will play the sound on a loop until it is explicitly stopped. This will make playing background audio rather simple. We can add a flag to the play_sound
function in the sound
module for the loop
parameter, as shown here:
fn create_track_source(ctx: &AudioContext, buffer: &AudioBuffer) -> Result<AudioBufferSourceNode> { let track_source = create_buffer_source(ctx)?; track_source.set_buffer(Some(&buffer)); connect_with_audio_node(&track_source, &ctx.destination())?; Ok(track_source) } pub enum LOOPING { ...