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

Playback controls not working with observers #130

Open
iiYese opened this issue Sep 6, 2024 · 1 comment
Open

Playback controls not working with observers #130

iiYese opened this issue Sep 6, 2024 · 1 comment

Comments

@iiYese
Copy link

iiYese commented Sep 6, 2024

Code to reproduce:

use bevy::{asset::io::file::FileAssetReader, prelude::*};
use bevy_kira_audio::prelude::{AudioChannel, AudioSource, *};

#[derive(Event)]
struct Load;

#[derive(Event)]
struct Play;

#[derive(Resource, Default)]
pub struct Channel;

fn load(
    _: Trigger<Load>,
    channel: Res<AudioChannel<Channel>>,
    mut sources: ResMut<Assets<AudioSource>>,
) {
    let sound = StaticSoundData::from_file(
        FileAssetReader::get_base_path()
            .join("assets")
            .join("track.ogg"),
        StaticSoundSettings::default(),
    )
    .unwrap();

    channel.play(sources.add(AudioSource { sound })).paused();
}

fn play(_: Trigger<Play>, channel: Res<AudioChannel<Channel>>) {
    channel.resume();
}

fn setup(mut cmds: Commands) {
    cmds.trigger(Load);
    cmds.trigger(Play);
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(AudioPlugin)
        .add_audio_channel::<Channel>()
        .observe(load)
        .observe(play)
        .add_systems(Startup, setup)
        .run();
}

There is just a single track.ogg file in assets.

@NiklasEi
Copy link
Owner

I don't think that this has much to do with observers. If you trigger the play observer in a system when the user clicks, the sound plays fine. I have not figured out yet why the resume in your code example does not work properly.

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

2 participants