bevy_kira_audio icon indicating copy to clipboard operation
bevy_kira_audio copied to clipboard

Playback controls not working with observers

Open iiYese opened this issue 5 months ago • 0 comments

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.

iiYese avatar Sep 06 '24 22:09 iiYese