SinkController

Struct SinkController 

Source
pub struct SinkController {
    pub handler: Handler,
}
Expand description

This handles device that plays out audio (e.g., headphone), so this is appropriate when dealing with audio playback devices and applications.

Fields§

§handler: Handler

Implementations§

Source§

impl SinkController

Source

pub fn create() -> Result<Self, ControllerError>

Examples found in repository?
examples/change_device_vol.rs (line 8)
6fn main() {
7    // create handler that calls functions on playback devices and apps
8    let mut handler = SinkController::create().unwrap();
9    let devices = handler
10        .list_devices()
11        .expect("Could not get list of playback devices");
12
13    println!("Playback Devices: ");
14    for device in &devices {
15        println!(
16            "[Index: {}] {}, [Volume: {}]",
17            device.index,
18            device.description.as_ref().unwrap(),
19            device.volume
20        );
21    }
22
23    let mut input = String::new();
24
25    print!("Select an index: ");
26    io::stdout().flush().expect("Failed to flush stdout");
27
28    io::stdin()
29        .read_line(&mut input)
30        .expect("Unable to read user input");
31
32    println!("Increasing volume by 5%...");
33
34    let device_index = input.trim().parse().expect("Invalid number");
35    handler.increase_device_volume_by_percent(device_index, 0.05);
36
37    println!(
38        "Volume set to [Volume: {}]",
39        handler
40            .get_device_by_index(device_index)
41            .expect("Failed to get device by index")
42            .volume
43    )
44}
Source

pub fn get_server_info(&mut self) -> Result<ServerInfo, ControllerError>

Trait Implementations§

Source§

impl AppControl<ApplicationInfo> for SinkController

Source§

fn list_applications(&mut self) -> Result<Vec<ApplicationInfo>, ControllerError>

Source§

fn get_app_by_index( &mut self, index: u32, ) -> Result<ApplicationInfo, ControllerError>

Source§

fn increase_app_volume_by_percent(&mut self, index: u32, delta: f64)

Source§

fn decrease_app_volume_by_percent(&mut self, index: u32, delta: f64)

Source§

fn move_app_by_index( &mut self, stream_index: u32, device_index: u32, ) -> Result<bool, ControllerError>

Source§

fn move_app_by_name( &mut self, stream_index: u32, device_name: &str, ) -> Result<bool, ControllerError>

Source§

fn set_app_mute( &mut self, index: u32, mute: bool, ) -> Result<bool, ControllerError>

Source§

impl DeviceControl<DeviceInfo> for SinkController

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.