Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicChannel doesn't hold any states/is_playing_sound() is always false #137

Open
PatrickChodowski opened this issue Dec 27, 2024 · 0 comments

Comments

@PatrickChodowski
Copy link

Version: Bevy 0.15/0.21

I wanted to use dynamic channels to play different sounds like background, walking sounds etc. I use an event to play the sound. Later in the system I am checking if given channel is playing sound and then replace it, if it is.


fn start(
    mut evs:      EventReader<PlaySound>,
    ass:          Res<AssetServer>,
    mut audio:    ResMut<DynamicAudioChannels>,
){  
    for ev in evs.read(){

        let mut audio_to_play: Option<PlayAudioCommand> = None;
        let Some(channel) = audio.get_channel(&ev.channel.to_str()) else {continue;};

        info!("{:?}", channel.states);

        if channel.is_playing_sound() {
            match ev.soundsos {
                SoundSOS::Abandon => {/* Do nothing, there is already a sound in a channel */}
                SoundSOS::Replace => {
                    channel.stop();
                    audio_to_play = Some(channel.play(ass.load(format!("sounds/{}.ogg", ev.sound_name))));
                }
            }
        } else {
            info!("NOT PLAYING SOUND");
            audio_to_play = Some(channel.play(ass.load(format!("sounds/{}.ogg", ev.sound_name))));
        }

....

Turns out the channel.is_playing_sound() returns always false, even though sound is playing (more and more of it :D) I checked the channel.states but they are always empty in this case. I tried to dig deeper but I saw "dyn" and backed off

tools::sounds: ev: PlaySound { channel: AnimationSounds, soundsos: Abandon, playback_rate: 1.0, sound_name: "steps/stepdirt_5", looped: false }
tools::sounds: {}
tools::sounds: NOT PLAYING SOUND
tools::sounds: ev: PlaySound { channel: AnimationSounds, soundsos: Abandon, playback_rate: 1.0, sound_name: "steps/stepdirt_7", looped: false }
tools::sounds: {}
tools::sounds: NOT PLAYING SOUND
tools::sounds: ev: PlaySound { channel: AnimationSounds, soundsos: Abandon, playback_rate: 1.0, sound_name: "steps/stepdirt_8", looped: false }
tools::sounds: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant