From 18c2924422c78453263b75ddcdc585b6d328e0ce Mon Sep 17 00:00:00 2001 From: Nils Hasenbanck Date: Sun, 29 Dec 2024 19:06:58 +0100 Subject: [PATCH] Fix background music playback I don't know yet if it's a bug in kira or working as designed. --- korangar_audio/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/korangar_audio/src/lib.rs b/korangar_audio/src/lib.rs index fd941838..78c92be3 100644 --- a/korangar_audio/src/lib.rs +++ b/korangar_audio/src/lib.rs @@ -800,7 +800,14 @@ impl EngineContext { } }; - let data = data.output_destination(&self.background_music_track).loop_region(..); + // Workaround: It seems kira drops the music as soon as it finishes, even though + // we defined the loop region to be the full region of the music. We shave off + // 50 ms of the music, so that the music never finishes, and we properly loop + // the music again. + let duration = data.duration().as_secs_f64() - 0.05; + let data = data.loop_region(..duration); + let data = data.output_destination(&self.background_music_track); + let handle = match self.manager.play(data) { Ok(handle) => handle, Err(_error) => {