1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::Error;
use rodio::{OutputStream, OutputStreamHandle, Sink};

pub struct NativeAudioPlayer {
    _output_stream: OutputStream,
    output_stream_handle: OutputStreamHandle,
}

impl NativeAudioPlayer {
    pub fn try_new_default_device() -> Result<Self, Error> {
        let (output_stream, output_stream_handle) =
            crate::common::output_stream_handle().ok_or(Error::FailedToCreateOutputStream)?;
        Ok(Self {
            _output_stream: output_stream,
            output_stream_handle,
        })
    }

    pub fn new_default_device() -> Self {
        Self::try_new_default_device().unwrap()
    }

    pub fn play_bytes(&self, bytes: &'static [u8]) -> Sink {
        crate::common::play_bytes(&self.output_stream_handle, bytes)
    }

    pub fn play_bytes_loop(&self, bytes: &'static [u8]) -> Sink {
        crate::common::play_bytes_loop(&self.output_stream_handle, bytes)
    }
}