mirror of
https://github.com/librespot-org/librespot.git
synced 2025-01-17 17:34: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,40 +6,54 @@ pub trait Sink {
|
|||
fn write(&self, data: &[i16]) -> io::Result<()>;
|
||||
}
|
||||
|
||||
pub struct PortAudioSink<'a>(portaudio::stream::Stream<'a, i16, i16>);
|
||||
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> {
|
||||
pub fn open() -> PortAudioSink<'a> {
|
||||
portaudio::initialize().unwrap();
|
||||
impl <'a> PortAudioSink<'a> {
|
||||
pub fn open() -> PortAudioSink<'a> {
|
||||
portaudio::initialize().unwrap();
|
||||
|
||||
let stream = portaudio::stream::Stream::open_default(
|
||||
0, 2, 44100.0,
|
||||
portaudio::stream::FRAMES_PER_BUFFER_UNSPECIFIED,
|
||||
None
|
||||
).unwrap();
|
||||
let stream = portaudio::stream::Stream::open_default(
|
||||
0, 2, 44100.0,
|
||||
portaudio::stream::FRAMES_PER_BUFFER_UNSPECIFIED,
|
||||
None
|
||||
).unwrap();
|
||||
|
||||
PortAudioSink(stream)
|
||||
PortAudioSink(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Sink for PortAudioSink<'a> {
|
||||
fn start(&self) -> io::Result<()> {
|
||||
self.0.start().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
fn stop(&self) -> io::Result<()> {
|
||||
self.0.stop().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
fn write(&self, data: &[i16]) -> io::Result<()> {
|
||||
match self.0.write(&data) {
|
||||
Ok(_) => (),
|
||||
Err(portaudio::PaError::OutputUnderflowed) => eprintln!("Underflow"),
|
||||
Err(e) => panic!("PA Error {}", e),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Drop for PortAudioSink<'a> {
|
||||
fn drop(&mut self) {
|
||||
portaudio::terminate().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Sink for PortAudioSink<'a> {
|
||||
fn start(&self) -> io::Result<()> {
|
||||
self.0.start().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
fn stop(&self) -> io::Result<()> {
|
||||
self.0.stop().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
fn write(&self, data: &[i16]) -> io::Result<()> {
|
||||
self.0.write(&data).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Drop for PortAudioSink<'a> {
|
||||
fn drop(&mut self) {
|
||||
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