mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Keep the sink open
Fix typo
This commit is contained in:
parent
6fed8d0413
commit
981b76bace
2 changed files with 22 additions and 23 deletions
|
@ -1142,7 +1142,7 @@ impl SpircTask {
|
||||||
// tracks in each frame either have a gid or uri (that may or may not be a valid track)
|
// tracks in each frame either have a gid or uri (that may or may not be a valid track)
|
||||||
// E.g - context based frames sometimes contain tracks with <spotify:meta:page:>
|
// E.g - context based frames sometimes contain tracks with <spotify:meta:page:>
|
||||||
|
|
||||||
let mut track_ref = self.state.get_track()[index as usize].clone();
|
let mut track_ref = self.state.get_track()[new_playlist_index as usize].clone();
|
||||||
let mut track_id = self.get_spotify_id_for_track(&track_ref);
|
let mut track_id = self.get_spotify_id_for_track(&track_ref);
|
||||||
while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable {
|
while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable {
|
||||||
warn!(
|
warn!(
|
||||||
|
|
|
@ -749,8 +749,8 @@ impl Future for PlayerInternal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.state.is_playing() && !self.sink_running {
|
if self.state.is_playing() {
|
||||||
self.start_sink();
|
self.ensure_sink_running();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.sink_running {
|
if self.sink_running {
|
||||||
|
@ -866,23 +866,24 @@ impl PlayerInternal {
|
||||||
position_ms as u64 * 441 / 10
|
position_ms as u64 * 441 / 10
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_sink(&mut self) {
|
fn ensure_sink_running(&mut self) {
|
||||||
match self.sink.start() {
|
if !self.sink_running {
|
||||||
Ok(()) => self.sink_running = true,
|
trace!("== Starting sink ==");
|
||||||
Err(err) => error!("Could not start audio: {}", err),
|
match self.sink.start() {
|
||||||
|
Ok(()) => self.sink_running = true,
|
||||||
|
Err(err) => error!("Could not start audio: {}", err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_sink_if_running(&mut self) {
|
fn ensure_sink_stopped(&mut self) {
|
||||||
if self.sink_running {
|
if self.sink_running {
|
||||||
self.stop_sink();
|
trace!("== Stopping sink ==");
|
||||||
|
self.sink.stop().unwrap();
|
||||||
|
self.sink_running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_sink(&mut self) {
|
|
||||||
self.sink.stop().unwrap();
|
|
||||||
self.sink_running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_player_stop(&mut self) {
|
fn handle_player_stop(&mut self) {
|
||||||
match self.state {
|
match self.state {
|
||||||
|
@ -906,7 +907,7 @@ impl PlayerInternal {
|
||||||
play_request_id,
|
play_request_id,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.stop_sink_if_running();
|
self.ensure_sink_stopped();
|
||||||
self.send_event(PlayerEvent::Stopped {
|
self.send_event(PlayerEvent::Stopped {
|
||||||
track_id,
|
track_id,
|
||||||
play_request_id,
|
play_request_id,
|
||||||
|
@ -934,7 +935,7 @@ impl PlayerInternal {
|
||||||
play_request_id,
|
play_request_id,
|
||||||
position_ms,
|
position_ms,
|
||||||
});
|
});
|
||||||
self.start_sink();
|
self.ensure_sink_running();
|
||||||
} else {
|
} else {
|
||||||
warn!("Player::play called from invalid state");
|
warn!("Player::play called from invalid state");
|
||||||
}
|
}
|
||||||
|
@ -951,7 +952,7 @@ impl PlayerInternal {
|
||||||
{
|
{
|
||||||
self.state.playing_to_paused();
|
self.state.playing_to_paused();
|
||||||
|
|
||||||
self.stop_sink_if_running();
|
self.ensure_sink_stopped();
|
||||||
let position_ms = Self::position_pcm_to_ms(stream_position_pcm);
|
let position_ms = Self::position_pcm_to_ms(stream_position_pcm);
|
||||||
self.send_event(PlayerEvent::Paused {
|
self.send_event(PlayerEvent::Paused {
|
||||||
track_id,
|
track_id,
|
||||||
|
@ -980,13 +981,12 @@ impl PlayerInternal {
|
||||||
|
|
||||||
if let Err(err) = self.sink.write(&packet.data()) {
|
if let Err(err) = self.sink.write(&packet.data()) {
|
||||||
error!("Could not write audio: {}", err);
|
error!("Could not write audio: {}", err);
|
||||||
self.stop_sink();
|
self.ensure_sink_stopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
self.stop_sink();
|
|
||||||
self.state.playing_to_end_of_track();
|
self.state.playing_to_end_of_track();
|
||||||
if let PlayerState::EndOfTrack {
|
if let PlayerState::EndOfTrack {
|
||||||
track_id,
|
track_id,
|
||||||
|
@ -1040,7 +1040,7 @@ impl PlayerInternal {
|
||||||
}
|
}
|
||||||
|
|
||||||
if start_playback {
|
if start_playback {
|
||||||
self.start_sink();
|
self.ensure_sink_running();
|
||||||
|
|
||||||
self.send_event(PlayerEvent::Playing {
|
self.send_event(PlayerEvent::Playing {
|
||||||
track_id,
|
track_id,
|
||||||
|
@ -1094,10 +1094,6 @@ impl PlayerInternal {
|
||||||
play,
|
play,
|
||||||
position_ms,
|
position_ms,
|
||||||
} => {
|
} => {
|
||||||
if self.state.is_playing() {
|
|
||||||
self.stop_sink_if_running();
|
|
||||||
}
|
|
||||||
|
|
||||||
// emit the correct player event
|
// emit the correct player event
|
||||||
match self.state {
|
match self.state {
|
||||||
PlayerState::Playing {
|
PlayerState::Playing {
|
||||||
|
@ -1228,6 +1224,9 @@ impl PlayerInternal {
|
||||||
// We need to load the track - either from scratch or by completing a preload.
|
// We need to load the track - either from scratch or by completing a preload.
|
||||||
// In any case we go into a Loading state to load the track.
|
// In any case we go into a Loading state to load the track.
|
||||||
if !load_command_processed {
|
if !load_command_processed {
|
||||||
|
|
||||||
|
self.ensure_sink_stopped();
|
||||||
|
|
||||||
self.send_event(PlayerEvent::Loading {
|
self.send_event(PlayerEvent::Loading {
|
||||||
track_id,
|
track_id,
|
||||||
play_request_id,
|
play_request_id,
|
||||||
|
|
Loading…
Reference in a new issue