mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-06 03:50:06 +02:00
![]() Spotify Connect does not allow you to move playback of a local file to the librespot device as it says that it "can't play this track". Note that this is slightly inconsistent as Spotify allows you to switch to a local file if librespot is already playing a non-local file, which currently fails with an error. However, it is possible for the desktop and iOS client to accept playback of local files. In looking at the PUT request sent to `connect-state/v1/devices/<id>` from the iOS client, it can be seen that it includes `audio/local` as an entry in the `supported_types` capability field. This commit introduces this field to the capabilities that librespot sends. For now, it is a complete lie as we do not support local file playback, but it will make the ongoing development of this feature easier, as we will not have to queue up a non-local track and attempt to switch to a local one. Testing shows that with this flag the "can't play this track" message disappears and allows librespot to (attempt) to play a local file before erroring out. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
README.md |
Connect
The connect module of librespot. Provides the option to create your own connect device and stream to it like any other official spotify client.
The [Spirc
] is the entrypoint to creating your own connect device. It can be
configured with the given [ConnectConfig
] options and requires some additional data
to start up the device.
When creating a new [Spirc
] it returns two items. The [Spirc
] itself, which is can
be used as to control the local connect device. And a Future
,
lets name it SpircTask
, that starts and executes the event loop of the connect device
when awaited.
A basic example in which the Spirc
and SpircTask
is used can be found here:
examples/play_connect.rs
.
Example
use std::{future::Future, thread};
use librespot_connect::{ConnectConfig, Spirc};
use librespot_core::{authentication::Credentials, Error, Session, SessionConfig};
use librespot_playback::{
audio_backend, mixer,
config::{AudioFormat, PlayerConfig},
mixer::{MixerConfig, NoOpVolume},
player::Player
};
async fn create_basic_spirc() -> Result<(), Error> {
let credentials = Credentials::with_access_token("access-token-here");
let session = Session::new(SessionConfig::default(), None);
let backend = audio_backend::find(None).expect("will default to rodio");
let player = Player::new(
PlayerConfig::default(),
session.clone(),
Box::new(NoOpVolume),
move || {
let format = AudioFormat::default();
let device = None;
backend(device, format)
},
);
let mixer = mixer::find(None).expect("will default to SoftMixer");
let (spirc, spirc_task): (Spirc, _) = Spirc::new(
ConnectConfig::default(),
session,
credentials,
player,
mixer(MixerConfig::default())?
).await?;
Ok(())
}