spotifyaudiosrc: Update to librespot 0.4

This commit is contained in:
Sebastian Dröge 2022-05-22 16:28:59 +03:00
parent d6fa921822
commit a0455b5e00
2 changed files with 12 additions and 7 deletions

View file

@ -12,7 +12,7 @@ rust-version = "1.57"
gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
once_cell = "1.0" once_cell = "1.0"
librespot = { version = "0.3", default-features = false } librespot = { version = "0.4", default-features = false }
tokio = "1.0" tokio = "1.0"
futures = "0.3" futures = "0.3"
anyhow = "1.0" anyhow = "1.0"

View file

@ -26,6 +26,7 @@ use librespot::playback::{
config::PlayerConfig, config::PlayerConfig,
convert::Converter, convert::Converter,
decoder::AudioPacket, decoder::AudioPacket,
mixer::NoOpVolume,
player::{Player, PlayerEvent}, player::{Player, PlayerEvent},
}; };
@ -326,7 +327,7 @@ impl SpotifyAudioSrc {
None None
}; };
let cache = Cache::new(credentials_cache, files_cache, max_size)?; let cache = Cache::new(credentials_cache, None, files_cache, max_size)?;
let credentials = match cache.credentials() { let credentials = match cache.credentials() {
Some(cached_cred) => { Some(cached_cred) => {
@ -358,7 +359,8 @@ impl SpotifyAudioSrc {
let state = self.state.clone(); let state = self.state.clone();
let session = Session::connect(SessionConfig::default(), credentials, Some(cache)).await?; let (session, _credentials) =
Session::connect(SessionConfig::default(), credentials, Some(cache), false).await?;
let player_config = PlayerConfig { let player_config = PlayerConfig {
passthrough: true, passthrough: true,
@ -370,7 +372,7 @@ impl SpotifyAudioSrc {
let sender_clone = sender.clone(); let sender_clone = sender.clone();
let (mut player, mut player_event_channel) = let (mut player, mut player_event_channel) =
Player::new(player_config, session, None, || { Player::new(player_config, session, Box::new(NoOpVolume), || {
Box::new(BufferSink { sender }) Box::new(BufferSink { sender })
}); });
@ -413,9 +415,12 @@ struct BufferSink {
} }
impl Sink for BufferSink { impl Sink for BufferSink {
fn write(&mut self, packet: &AudioPacket, _converter: &mut Converter) -> SinkResult<()> { fn write(&mut self, packet: AudioPacket, _converter: &mut Converter) -> SinkResult<()> {
let ogg = packet.oggdata().unwrap(); let oggdata = match packet {
let buffer = gst::Buffer::from_slice(Vec::from(ogg)); AudioPacket::OggData(data) => data,
AudioPacket::Samples(_) => unimplemented!(),
};
let buffer = gst::Buffer::from_slice(oggdata);
// ignore if sending fails as that means the source element is being shutdown // ignore if sending fails as that means the source element is being shutdown
let _ = self.sender.send(Message::Buffer(buffer)); let _ = self.sender.send(Message::Buffer(buffer));