mirror of
https://github.com/librespot-org/librespot.git
synced 2025-01-27 17:44:04 +00:00
Forgot to add some files in previous commit.
This commit is contained in:
parent
9274a6bfb3
commit
0973469120
2 changed files with 42 additions and 33 deletions
|
@ -1,4 +1,3 @@
|
|||
use portaudio;
|
||||
use std::io;
|
||||
|
||||
pub trait Sink {
|
||||
|
@ -7,6 +6,10 @@ pub trait Sink {
|
|||
fn write(&self, data: &[i16]) -> io::Result<()>;
|
||||
}
|
||||
|
||||
mod portaudio_sink {
|
||||
use audio_sink::Sink;
|
||||
use std::io;
|
||||
use portaudio;
|
||||
pub struct PortAudioSink<'a>(portaudio::stream::Stream<'a, i16, i16>);
|
||||
|
||||
impl <'a> PortAudioSink<'a> {
|
||||
|
@ -33,7 +36,12 @@ impl <'a> Sink for PortAudioSink<'a> {
|
|||
Ok(())
|
||||
}
|
||||
fn write(&self, data: &[i16]) -> io::Result<()> {
|
||||
self.0.write(&data).unwrap();
|
||||
match self.0.write(&data) {
|
||||
Ok(_) => (),
|
||||
Err(portaudio::PaError::OutputUnderflowed) => eprintln!("Underflow"),
|
||||
Err(e) => panic!("PA Error {}", e),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +51,9 @@ impl <'a> Drop for PortAudioSink<'a> {
|
|||
portaudio::terminate().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub type DefaultSink = portaudio_sink::PortAudioSink<'static>;
|
||||
|
||||
|
|
|
@ -107,14 +107,10 @@ fn main() {
|
|||
let reusable_credentials = session.login(credentials).unwrap();
|
||||
reusable_credentials.save_to_file(credentials_path);
|
||||
|
||||
portaudio::initialize().unwrap();
|
||||
|
||||
let player = Player::new(session.clone(), || DefaultSink::open());
|
||||
let spirc = SpircManager::new(session.clone(), player);
|
||||
thread::spawn(move || spirc.run());
|
||||
|
||||
portaudio::terminate().unwrap();
|
||||
|
||||
loop {
|
||||
session.poll();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue