Restart queue if pressing play when stopped (#399)

* Restart queue if pressing play when stopped

* Remove FinishedTrack from match

* Formatting
This commit is contained in:
André Andersson
2021-01-19 21:47:41 +01:00
committed by GitHub
parent cfb91493a5
commit 92335594bc
3 changed files with 14 additions and 9 deletions

View File

@@ -400,9 +400,9 @@ fn run_dbus_server(
});
let method_playpause = {
let spotify = spotify.clone();
let queue = queue.clone();
f.method("PlayPause", (), move |m| {
spotify.toggleplayback();
queue.toggleplayback();
Ok(vec![m.msg.method_return()])
})
};

View File

@@ -7,9 +7,9 @@ use notify_rust::Notification;
use rand::prelude::*;
use strum_macros::Display;
use crate::config::Config;
use crate::playable::Playable;
use crate::spotify::Spotify;
use crate::{config::Config, spotify::PlayerEvent};
#[derive(Display, Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
pub enum RepeatSetting {
@@ -264,7 +264,16 @@ impl Queue {
}
pub fn toggleplayback(&self) {
self.spotify.toggleplayback();
match self.spotify.get_current_status() {
PlayerEvent::Playing | PlayerEvent::Paused => {
self.spotify.toggleplayback();
}
PlayerEvent::Stopped => match self.next_index() {
Some(_) => self.next(false),
None => self.play(0, false, false),
},
_ => (),
}
}
pub fn stop(&self) {

View File

@@ -890,11 +890,7 @@ impl Spotify {
}
pub fn toggleplayback(&self) {
let status = self
.status
.read()
.expect("could not acquire read lock on player state");
match *status {
match self.get_current_status() {
PlayerEvent::Playing => self.pause(),
PlayerEvent::Paused => self.play(),
_ => (),