#How do I know duration of an AudioSource?
6 messages · Page 1 of 1 (latest)
With audio_assets: Res<Assets<Source>> and audio_assets.get(your_audio_source_handle).total_duration() I think? https://docs.rs/bevy/latest/bevy/audio/trait.Source.html#tymethod.total_duration
A source of samples.
Source is a trait, not an asset
yeah, sorry ><"
Possible solution:
fn get_duration(source: AudioSource) -> Option<Duration> {
source.decoder().total_duration()
}
tested on wav audio files, it works.
seems to be inefficient solution for a runtime, better would be to get audio durations on loading assets, then save them somewhere in Resources