primitives/prelude/traits/audio_manager.rs
1use crate::prelude::AudioChannel;
2
3/// Provides functions to control playback of audio: sounds, music etc.
4///
5pub trait AudioManager {
6 /// If true all audio playback is silenced.
7 fn is_mute(&self) -> bool;
8
9 /// Set the audio playback is silenced.
10 fn set_mute(&self, val: bool);
11
12 /// Begin playback of any specified sound. Optional parameters allow further control.
13 ///
14 /// # Arguments
15 ///
16 /// * `id` - The unique id of the audio media asset. Can be the className of a loaded asset library.
17 /// * `audio_channel_type` - Sounds can be assigned specific channels to allow transformation of groups of related sounds. (optional)
18 /// * `loops` - How many times the specified sound should repeat. Set to -1 for continual loop. (optional, default: 1)
19 /// * `start_time` - Time displacement (ms) from the start of the sound file. (optional: default: 0)
20 /// * `volume` - Adjusts this sound's amplitude relative to the audioChannel. 0...1: 0 is silent, 1 is full. (optional, default 1.0)
21 /// * `pan` - Adjusts this sound's stereo effect relative to the audioChannel. -1...1: -1 is left channel only, 0 is central, 1 is right channel only. (optional, default: 0.0)
22 /// * `is_ignored_if_playing` - If true and this sound is already playing in the specified channel the start request will be skipped. If false there is a potential for the same sound to play over the top of itself. (optional, default: false)
23 /// * `on_complete_callback` - Callback method to execute on sound complete. (optional, default: None)
24 fn start(
25 &self,
26 id: String,
27 audio_channel_type: Option<AudioChannel>,
28 loops: Option<i32>,
29 start_time: Option<i32>,
30 volume: Option<f32>,
31 pan: Option<f32>,
32 is_ignored_if_playing: Option<bool>,
33 on_complete_callback: Option<Box<dyn Fn()>>,
34 );
35
36 /// End playback of any specified sound. To stop all sounds on all channels, leave all parameters blank.
37 ///
38 /// # Arguments
39 ///
40 /// * `id` - The unique id of the audio media asset intended to be stopped. If null will stop all sounds on the specific audioChannel. (optional)
41 /// * `audio_channel_type` - If specified will only stop sounds assigned to this channel. (optional)
42 fn stop(&self, id: Option<String>, audio_channel_type: Option<AudioChannel>);
43
44 /// Adjusts the playback of any specified sound. To adjust all sounds, ommit id and audio_channel_type.
45 ///
46 /// # Arguments
47 ///
48 /// * `id` - The unique id of the audio media asset intended to be transformed. If null will transform all sounds on the specific audioChannel. (optional)
49 /// * `audio_channel_type` - If specified will only transform sounds assigned to this channel. (optional)
50 /// * `volume` - Adjusts this sound's amplitude relative to the audioChannel. 0...1: 0 is silent, 1 is full. (optional, default: 1.0)
51 /// * `pan` - Adjusts this sound's stereo effect relative to the audioChannel. -1...1: -1 is left channel only, 0 is central, 1 is right channel only. (optional, default: 0.0)
52 /// * `as_relative` - If true will adjust sounds relative to their original transformation. If false will set them as absolute values. (optional, default: false)
53 ///
54 fn transform(
55 &self,
56 id: Option<String>,
57 audio_channel_type: Option<AudioChannel>,
58 volume: Option<f32>,
59 pan: Option<f32>,
60 as_relative: Option<bool>,
61 );
62
63 /// Discover if a specified sound is playing.
64 /// Returns true if a match is found, otherwise false.
65 ///
66 /// * `id` - The unique id of the audio media asset under investigation. If null will search entire audioChannel for activity. (optional)
67 /// * `audio_channel_type` - If specified will only investigate the specified channel. If ommitted will investigate all channels. (optional)
68 ///
69 fn is_playing(&self, id: Option<String>, audio_channel_type: Option<AudioChannel>) -> bool;
70}