[GH-ISSUE #603] [Question] Why does librespot_playback::audio_backend::find return a None option even if the backend is valid? #377

Closed
opened 2026-02-27 19:30:18 +03:00 by kerem · 8 comments
Owner

Originally created by @Occhioverde on GitHub (Feb 14, 2021).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/603

Hi all!
Maybe I'm about to ask a stupid question, but I really can't find a solution.

The problem is this: I'm trying to write a very simple application that, after receiving the credentials, plays a song from Spotify (whose ID is written directly in the code) but I can not create an instance of Player.
When I try to search the backend using the function librespot_playback::audio_backend::find, in fact, the program crashes saying it has received a None value. Obviously this would be normal if it wasn't that the specified backend (rodio) was told to be available (I checked the backends using the command target/release/librespot -n test --backend '?' and librespot listed me rodio (default), pipe and subprocess).

If it helps, this is my source code:

fn login(username: QString, password: QString) {
    let username: String = QString::into(username);
    let password: String = QString::into(password);

    let mut core = Core::new().unwrap();
    let handle = core.handle();
    let session_config = SessionConfig::default();
    let player_config = PlayerConfig::default();

    let credentials = Credentials::with_password(username, password);

    println!("Connecting ...");
    let session = core
        .run(Session::connect(session_config, credentials, None, handle))
        .unwrap();
    println!("Connected!");
    let create_mixer = librespot_playback::mixer::find(Some("softvol".to_owned())).expect("could not create softvol mixer");
    let mixer = create_mixer(None);

    let backend_string: Option<String> = Some(String::from("rodio"));
    let device_string: Option<String> = None;
    let backend = audio_backend::find(backend_string).unwrap();

    let mut spot_player = Player::new(player_config, session, mixer.get_audio_filter(), move || (backend)(device_string)).0;
    spot_player.load(SpotifyId::from_uri("spotify:track:1y9QiBBJynizfLbYjHM2Sg").unwrap(), true, 0);
}

I am aware that, in all likelihood, this problem is from some error in my code, but I hope someone can help me solve it.
I thank you in advance for your help.

Originally created by @Occhioverde on GitHub (Feb 14, 2021). Original GitHub issue: https://github.com/librespot-org/librespot/issues/603 Hi all! Maybe I'm about to ask a stupid question, but I really can't find a solution. The problem is this: I'm trying to write a very simple application that, after receiving the credentials, plays a song from Spotify (whose ID is written directly in the code) but I can not create an instance of Player. When I try to search the backend using the function `librespot_playback::audio_backend::find`, in fact, the program crashes saying it has received a None value. Obviously this would be normal if it wasn't that the specified backend (`rodio`) was told to be available (I checked the backends using the command `target/release/librespot -n test --backend '?'` and librespot listed me `rodio (default)`, `pipe` and `subprocess`). If it helps, this is my source code: ```rust fn login(username: QString, password: QString) { let username: String = QString::into(username); let password: String = QString::into(password); let mut core = Core::new().unwrap(); let handle = core.handle(); let session_config = SessionConfig::default(); let player_config = PlayerConfig::default(); let credentials = Credentials::with_password(username, password); println!("Connecting ..."); let session = core .run(Session::connect(session_config, credentials, None, handle)) .unwrap(); println!("Connected!"); let create_mixer = librespot_playback::mixer::find(Some("softvol".to_owned())).expect("could not create softvol mixer"); let mixer = create_mixer(None); let backend_string: Option<String> = Some(String::from("rodio")); let device_string: Option<String> = None; let backend = audio_backend::find(backend_string).unwrap(); let mut spot_player = Player::new(player_config, session, mixer.get_audio_filter(), move || (backend)(device_string)).0; spot_player.load(SpotifyId::from_uri("spotify:track:1y9QiBBJynizfLbYjHM2Sg").unwrap(), true, 0); } ``` I am aware that, in all likelihood, this problem is from some error in my code, but I hope someone can help me solve it. I thank you in advance for your help.
kerem closed this issue 2026-02-27 19:30:18 +03:00
Author
Owner

@Johannesd3 commented on GitHub (Feb 14, 2021):

Did you enable the rodio-backend feature flag in your Cargo.toml?

<!-- gh-comment-id:778842857 --> @Johannesd3 commented on GitHub (Feb 14, 2021): Did you enable the `rodio-backend` feature flag in your `Cargo.toml`?
Author
Owner

@Occhioverde commented on GitHub (Feb 14, 2021):

No, I didn't know that was necessary.
What do I need to do to activate it? Pardon the question, but, as you probably noticed, I'm quite new to Rust...

<!-- gh-comment-id:778843280 --> @Occhioverde commented on GitHub (Feb 14, 2021): No, I didn't know that was necessary. What do I need to do to activate it? Pardon the question, but, as you probably noticed, I'm quite new to Rust...
Author
Owner

@Johannesd3 commented on GitHub (Feb 14, 2021):

I'm not sure if it's necessary since it should be enabled by default. However, it would be like this:

librespot = { version = "0.1.3", features = ["rodio-backend"] }

Does "pipe" work as backend?

<!-- gh-comment-id:778844000 --> @Johannesd3 commented on GitHub (Feb 14, 2021): I'm not sure if it's necessary since it should be enabled by default. However, it would be like this: ```toml librespot = { version = "0.1.3", features = ["rodio-backend"] } ``` Does `"pipe"` work as backend?
Author
Owner

@Occhioverde commented on GitHub (Feb 14, 2021):

pipe does not throw errors, but it does not play audio. From what I understand, however, this is normal due to the fact that pipe generates a stream of data without actually sending it to any backend.

As for adding the rodio-backend, so far I've imported librespot_core and librespot_playback separately. How can I access them through librespot?

<!-- gh-comment-id:778847254 --> @Occhioverde commented on GitHub (Feb 14, 2021): `pipe` does not throw errors, but it does not play audio. From what I understand, however, this is normal due to the fact that pipe generates a stream of data without actually sending it to any backend. As for adding the `rodio-backend`, so far I've imported `librespot_core` and `librespot_playback` separately. How can I access them through `librespot`?
Author
Owner

@Johannesd3 commented on GitHub (Feb 14, 2021):

Ah, this makes sense, librespot_playback doesn't set default features. Just do the same as I suggested above with librespot_playback instead.

<!-- gh-comment-id:778847471 --> @Johannesd3 commented on GitHub (Feb 14, 2021): Ah, this makes sense, `librespot_playback` doesn't set default features. Just do the same as I suggested above with `librespot_playback` instead.
Author
Owner

@Occhioverde commented on GitHub (Feb 14, 2021):

Now the program doesn't seem to throw errors anymore, but the playback still doesn't start.
No sound can be heard and the official Spotify apps don't detect connected devices.

<!-- gh-comment-id:778848984 --> @Occhioverde commented on GitHub (Feb 14, 2021): Now the program doesn't seem to throw errors anymore, but the playback still doesn't start. No sound can be heard and the official Spotify apps don't detect connected devices.
Author
Owner

@Johannesd3 commented on GitHub (Feb 14, 2021):

The official Spotify apps won't detect your device unless you use the librespot_connect crate. Just take a look at the source code of librespot or spotifyd to see how it works.

I can't tell you though why there's no playback.

<!-- gh-comment-id:778849871 --> @Johannesd3 commented on GitHub (Feb 14, 2021): The official Spotify apps won't detect your device unless you use the `librespot_connect` crate. Just take a look at the source code of librespot or spotifyd to see how it works. I can't tell you though why there's no playback.
Author
Owner

@Occhioverde commented on GitHub (Feb 14, 2021):

Alright, thanks for the help anyway.
At least I solved part of the problem....

<!-- gh-comment-id:778850497 --> @Occhioverde commented on GitHub (Feb 14, 2021): Alright, thanks for the help anyway. At least I solved part of the problem....
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#377
No description provided.