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: HandlerImplementations§
Source§impl SinkController
impl SinkController
Sourcepub fn create() -> Result<Self, ControllerError>
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}pub fn get_server_info(&mut self) -> Result<ServerInfo, ControllerError>
Trait Implementations§
Source§impl AppControl<ApplicationInfo> for SinkController
impl AppControl<ApplicationInfo> for SinkController
fn list_applications(&mut self) -> Result<Vec<ApplicationInfo>, ControllerError>
fn get_app_by_index( &mut self, index: u32, ) -> Result<ApplicationInfo, ControllerError>
fn increase_app_volume_by_percent(&mut self, index: u32, delta: f64)
fn decrease_app_volume_by_percent(&mut self, index: u32, delta: f64)
fn move_app_by_index( &mut self, stream_index: u32, device_index: u32, ) -> Result<bool, ControllerError>
fn move_app_by_name( &mut self, stream_index: u32, device_name: &str, ) -> Result<bool, ControllerError>
fn set_app_mute( &mut self, index: u32, mute: bool, ) -> Result<bool, ControllerError>
Source§impl DeviceControl<DeviceInfo> for SinkController
impl DeviceControl<DeviceInfo> for SinkController
fn get_default_device(&mut self) -> Result<DeviceInfo, ControllerError>
fn set_default_device(&mut self, name: &str) -> Result<bool, ControllerError>
fn list_devices(&mut self) -> Result<Vec<DeviceInfo>, ControllerError>
fn get_device_by_index( &mut self, index: u32, ) -> Result<DeviceInfo, ControllerError>
fn get_device_by_name( &mut self, name: &str, ) -> Result<DeviceInfo, ControllerError>
fn set_device_volume_by_index(&mut self, index: u32, volume: &ChannelVolumes)
fn set_device_volume_by_name(&mut self, name: &str, volume: &ChannelVolumes)
fn set_device_mute_by_index(&mut self, index: u32, mute: bool)
fn set_device_mute_by_name(&mut self, name: &str, mute: bool)
fn increase_device_volume_by_percent(&mut self, index: u32, delta: f64)
fn decrease_device_volume_by_percent(&mut self, index: u32, delta: f64)
Auto Trait Implementations§
impl Freeze for SinkController
impl !RefUnwindSafe for SinkController
impl !Send for SinkController
impl !Sync for SinkController
impl Unpin for SinkController
impl UnsafeUnpin for SinkController
impl !UnwindSafe for SinkController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more