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-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
once_cell = "1.0"
librespot = { version = "0.3", default-features = false }
librespot = { version = "0.4", default-features = false }
tokio = "1.0"
futures = "0.3"
anyhow = "1.0"

View file

@ -26,6 +26,7 @@ use librespot::playback::{
config::PlayerConfig,
convert::Converter,
decoder::AudioPacket,
mixer::NoOpVolume,
player::{Player, PlayerEvent},
};
@ -326,7 +327,7 @@ impl SpotifyAudioSrc {
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() {
Some(cached_cred) => {
@ -358,7 +359,8 @@ impl SpotifyAudioSrc {
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 {
passthrough: true,
@ -370,7 +372,7 @@ impl SpotifyAudioSrc {
let sender_clone = sender.clone();
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 })
});
@ -413,9 +415,12 @@ struct BufferSink {
}
impl Sink for BufferSink {
fn write(&mut self, packet: &AudioPacket, _converter: &mut Converter) -> SinkResult<()> {
let ogg = packet.oggdata().unwrap();
let buffer = gst::Buffer::from_slice(Vec::from(ogg));
fn write(&mut self, packet: AudioPacket, _converter: &mut Converter) -> SinkResult<()> {
let oggdata = match packet {
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
let _ = self.sender.send(Message::Buffer(buffer));