Browse and listen to thousands of radio stations across the globe right from your terminal ๐ŸŒŽ ๐Ÿ“ป ๐ŸŽตโœจ
radio rust tokio web-radio command-line-tool tui

os_media_controls: OsMediaControls: try_recv_os_event() & send_to_os()

+32
+32
src/os_media_controls.rs
··· 33 33 event_receiver, 34 34 }) 35 35 } 36 + 37 + /// Try to receive event produced by the operating system. 38 + /// 39 + /// Is [`None`] if no event is produced. 40 + pub fn try_recv_os_event(&mut self) -> Option<souvlaki::MediaControlEvent> { 41 + self.event_receiver.try_recv().ok() 42 + } 43 + 44 + /// Send the given [`Command`] to the operating system. 45 + pub fn send_to_os(&mut self, command: Command) -> Result<(), souvlaki::Error> { 46 + match command { 47 + Command::Play => self 48 + .controls 49 + .set_playback(souvlaki::MediaPlayback::Playing { progress: None }), 50 + Command::Pause => self 51 + .controls 52 + .set_playback(souvlaki::MediaPlayback::Paused { progress: None }), 53 + Command::SetVolume(volume) => self.controls.set_volume(volume), 54 + Command::SetMetadata(metadata) => self.controls.set_metadata(metadata), 55 + } 56 + } 57 + } 58 + 59 + /// Commands understood by OS media controls. 60 + #[derive(Debug, Clone)] 61 + pub enum Command<'a> { 62 + Play, 63 + Pause, 64 + /// Volume must be between `0.0..=1.0`. 65 + SetVolume(f64), 66 + /// Set the [`souvlaki::MediaMetadata`]. 67 + SetMetadata(souvlaki::MediaMetadata<'a>), 36 68 }