1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use core::{
    assets::{asset::AssetId, database::AssetsDatabase},
    ecs::Entity,
    Scalar,
};
use std::sync::{atomic::AtomicBool, Arc};

#[derive(Debug, Clone)]
pub enum AudioPlayState {
    Ended(bool),
    State(bool),
}

#[derive(Debug, Clone)]
pub struct AudioState {
    pub current_time: Option<Scalar>,
    pub is_playing: AudioPlayState,
}

pub trait Audio: Send + Sync {
    #[allow(clippy::too_many_arguments)]
    fn create_source(
        &mut self,
        entity: Entity,
        data: &[u8],
        streaming: bool,
        looped: bool,
        playback_rate: Scalar,
        volume: Scalar,
        play: bool,
        notify_ready: Arc<AtomicBool>,
    );
    fn destroy_source(&mut self, entity: Entity);
    fn has_source(&mut self, entity: Entity) -> bool;
    fn update_source(
        &mut self,
        entity: Entity,
        looped: bool,
        playback_rate: Scalar,
        volume: Scalar,
        play: Option<bool>,
    );
    fn get_source_state(&self, entity: Entity) -> Option<AudioState>;
    fn get_asset_id(&self, path: &str) -> Option<AssetId>;
    fn update_cache(&mut self, _assets: &AssetsDatabase) {}
}