allow play to be pressed if stopped but playlist not empty

This commit is contained in:
Erica Z 2024-10-26 17:46:15 +02:00
parent a82b5b0475
commit f240424774
3 changed files with 17 additions and 7 deletions

View file

@ -237,12 +237,18 @@ public class Playbin : GLib.Object {
}
public void play () {
assert (this.state != PlaybinState.STOPPED);
this.state = PlaybinState.PLAYING;
debug ("setting state to playing");
var ret = this.mpv.set_property_flag("pause", false);
if (ret != 0) {
debug (@"failed to set state to playing ($(ret)): $(ret.to_string())");
if (this.state == PlaybinState.STOPPED) {
// allow only when playlist is not empty
// and start from the top
assert (this._play_queue.get_n_items () > 0);
this.select_track (0);
} else {
this.state = PlaybinState.PLAYING;
debug ("setting state to playing");
var ret = this.mpv.set_property_flag("pause", false);
if (ret != 0) {
debug (@"failed to set state to playing ($(ret)): $(ret.to_string())");
}
}
}

View file

@ -119,7 +119,7 @@ template $UiPlaybar: Box {
Button {
icon-name: bind $play_pause_icon_name (template.playbin as <$Playbin>.state as <$PlaybinState>) as <string>;
valign: center;
sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as <bool>;
sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play_queue_position) as <bool>;
clicked => $on_play_pause_clicked ();
}

View file

@ -41,6 +41,10 @@ class Ui.Playbar : Gtk.Box {
return state != PlaybinState.STOPPED;
}
[GtkCallback] private bool can_press_play (PlaybinState state, uint n_items) {
return state != PlaybinState.STOPPED || n_items > 0;
}
[GtkCallback] private string mute_button_icon_name (bool mute) {
return mute ? "audio-volume-muted" : "audio-volume-high";
}