SystemAudioVolume

Struct SystemAudioVolume 

Source
pub struct SystemAudioVolume;
Expand description

Controls for the system volume.

Implementations§

Source§

impl SystemAudioVolume

Source

pub fn get_gain() -> f32

Get the current system volume.

Examples found in repository?
examples/system_audio_volume.rs (line 11)
10fn main() {
11    let original_gain = SystemAudioVolume::get_gain();
12    println!("System gain is currently set at {original_gain}");
13
14    delay();
15
16    println!("Halving the gain 🤫");
17    SystemAudioVolume::set_gain(original_gain / 2.0);
18
19    delay();
20
21    println!("Muting 🔇");
22    SystemAudioVolume::mute();
23
24    delay();
25
26    println!("Unmuting 🔊");
27    SystemAudioVolume::unmute();
28
29    delay();
30
31    print!("Putting it back to how you had it 🧹");
32    SystemAudioVolume::set_gain(original_gain);
33}
Source

pub fn set_gain(gain: f32)

Set the system volume.

Examples found in repository?
examples/system_audio_volume.rs (line 17)
10fn main() {
11    let original_gain = SystemAudioVolume::get_gain();
12    println!("System gain is currently set at {original_gain}");
13
14    delay();
15
16    println!("Halving the gain 🤫");
17    SystemAudioVolume::set_gain(original_gain / 2.0);
18
19    delay();
20
21    println!("Muting 🔇");
22    SystemAudioVolume::mute();
23
24    delay();
25
26    println!("Unmuting 🔊");
27    SystemAudioVolume::unmute();
28
29    delay();
30
31    print!("Putting it back to how you had it 🧹");
32    SystemAudioVolume::set_gain(original_gain);
33}
Source

pub fn is_muted() -> bool

Returns true if the system audio output is muted.

Source

pub fn mute()

Mute the system audio output.

Examples found in repository?
examples/system_audio_volume.rs (line 22)
10fn main() {
11    let original_gain = SystemAudioVolume::get_gain();
12    println!("System gain is currently set at {original_gain}");
13
14    delay();
15
16    println!("Halving the gain 🤫");
17    SystemAudioVolume::set_gain(original_gain / 2.0);
18
19    delay();
20
21    println!("Muting 🔇");
22    SystemAudioVolume::mute();
23
24    delay();
25
26    println!("Unmuting 🔊");
27    SystemAudioVolume::unmute();
28
29    delay();
30
31    print!("Putting it back to how you had it 🧹");
32    SystemAudioVolume::set_gain(original_gain);
33}
Source

pub fn unmute()

Unmute the system audio output.

Examples found in repository?
examples/system_audio_volume.rs (line 27)
10fn main() {
11    let original_gain = SystemAudioVolume::get_gain();
12    println!("System gain is currently set at {original_gain}");
13
14    delay();
15
16    println!("Halving the gain 🤫");
17    SystemAudioVolume::set_gain(original_gain / 2.0);
18
19    delay();
20
21    println!("Muting 🔇");
22    SystemAudioVolume::mute();
23
24    delay();
25
26    println!("Unmuting 🔊");
27    SystemAudioVolume::unmute();
28
29    delay();
30
31    print!("Putting it back to how you had it 🧹");
32    SystemAudioVolume::set_gain(original_gain);
33}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.