Replies: 7 comments
-
Please provide the code part where you spawn the |
Beta Was this translation helpful? Give feedback.
-
Sure, here is the constructor: impl MusicImpl {
pub async fn new() -> Result<MusicImpl, MusicError> {
let config = SessionConfig::default();
let player_config = PlayerConfig::default();
let audio_format = AudioFormat::default();
let backend = audio_backend::find(None).ok_or(MusicError::AudioBackendNotFound)?;
let cache = Cache::new(Some("cache"), Some("cache"), Some("cache"), None).map_err(|e| MusicError::CacheSetupError)?;
let session = Session::new(config, Some(cache.clone()));
println!("Starting discovery");
let mut disco: Discovery = Discovery::builder(session.device_id(), &session.client_id())
.name("Boombox")
.device_type(DeviceType::Speaker)
.zeroconf_backend(discovery::find(None).expect("Couldn't find discovery"))
.launch()
.map_err(|e| MusicError::ZeroconfSetupError(e))?;
let credentials = match cache.credentials() {
Some(c) => {
println!("Using cache credentials for {}", c.username.clone().unwrap_or("?".to_string()));
c
},
None => {
println!("Waiting for credentials via discovery");
disco.next().await.expect("No credentials?")
}
};
let mixer = mixer::find(None).ok_or(MusicError::MixerNotFound)?;
let mixer_config = MixerConfig::default();
let player = Player::new(
player_config,
session.clone(),
mixer(mixer_config.clone()).get_soft_volume(),
move || backend(None, audio_format),
);
let mut connect_config = ConnectConfig::default();
connect_config.name = "Boombox".to_string();
connect_config.device_type = DeviceType::Speaker;
let (spirc, spirc_task) = Spirc::new(
connect_config,
session,
credentials,
player.clone(),
mixer(mixer_config),
)
.await
.map_err(|e| MusicError::SpircSetupError(e))?;
spirc.activate().unwrap();
let handle = tokio::spawn(spirc_task);
Ok(MusicImpl { player, spirc, spirc_handle: handle })
}
} |
Beta Was this translation helpful? Give feedback.
-
Hmm, I tested your issue with the tokio::spawn(spirc_task);
loop {
tokio::time::sleep(Duration::from_secs(5)).await;
spirc.play_pause()?
} My test is based on the latest dev version. Which version did you use? But from everything provided I don't see any obvious issue when handling the |
Beta Was this translation helpful? Give feedback.
-
I think the best way forward would be if you could provide a minimal version of your issue to us. The easiest way would be to check in the minimal version on github and share the link to it. Then we can maybe help you, otherwise this issue seems out of our control. (At least from my perspective currently) |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering and sorry for the delay. I was using the |
Beta Was this translation helpful? Give feedback.
-
Just tested, it works correctly when running the |
Beta Was this translation helpful? Give feedback.
-
Turning this into a discussion, as I don't believe it's an issue with librepot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using librespot as a library for a player I've developping (which reads NFC tags and plays the corresponding music). This works fine, but I tried to refactor the code so that I can control the playback with buttons on the box. I moved the logic to a
tokio
task, and nothing happens anymore. The player is not playing any music, nor pausing / skipping to the next song.To make it clearer, here is the code that works
And here is what I have tried:
In the background, the
music_player
is just delegating to a Spirc instance (callingload
,next
,play_pause
). Thespirc
is created inMusicPlayer::new()
, and thespirc_task
is spawn there too. I'm really confused, but I'm thinking that the spirc might not be working in this context ? Do you have any idea ?Thanks a lot !
Beta Was this translation helpful? Give feedback.
All reactions