Skip to main content

thedes_tui_core/audio/device/
null.rs

1use std::borrow::Cow;
2
3use crate::audio::device::{
4    AudioDevice,
5    AudioSinkDevice,
6    CheckPlayStatusError,
7    ClearSinkError,
8    OpenSinkError,
9    PauseSinkError,
10    PlayNowError,
11    ResumeSinkError,
12    SetVolumeError,
13};
14
15pub fn open() -> Box<dyn AudioDevice> {
16    Box::new(NullAudioDevice)
17}
18
19#[derive(Debug, Clone, Copy)]
20struct NullAudioDevice;
21
22impl AudioDevice for NullAudioDevice {
23    fn open_sink(&mut self) -> Result<Box<dyn AudioSinkDevice>, OpenSinkError> {
24        Ok(Box::new(NullAudioSinkDevice))
25    }
26}
27
28#[derive(Debug, Clone, Copy)]
29struct NullAudioSinkDevice;
30
31impl AudioSinkDevice for NullAudioSinkDevice {
32    fn play_now(
33        &mut self,
34        _bytes: Cow<'static, [u8]>,
35    ) -> Result<(), PlayNowError> {
36        Ok(())
37    }
38
39    fn set_volume(&mut self, _volume: f32) -> Result<(), SetVolumeError> {
40        Ok(())
41    }
42
43    fn pause(&mut self) -> Result<(), PauseSinkError> {
44        Ok(())
45    }
46
47    fn resume(&mut self) -> Result<(), ResumeSinkError> {
48        Ok(())
49    }
50
51    fn clear(&mut self) -> Result<(), ClearSinkError> {
52        Ok(())
53    }
54
55    fn is_playing(&self) -> Result<bool, CheckPlayStatusError> {
56        Ok(false)
57    }
58}