diff --git a/src/playbin.vala b/src/playbin.vala index 4549202..5e71bec 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -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())"); + } } } diff --git a/src/ui/playbar.blp b/src/ui/playbar.blp index d44610f..83ef6c6 100644 --- a/src/ui/playbar.blp +++ b/src/ui/playbar.blp @@ -119,7 +119,7 @@ template $UiPlaybar: Box { Button { icon-name: bind $play_pause_icon_name (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; valign: center; - sensitive: bind $playbin_active (template.playbin as <$Playbin>.state as <$PlaybinState>) as ; + sensitive: bind $can_press_play (template.playbin as <$Playbin>.state as <$PlaybinState>, template.playbin as <$Playbin>.play_queue_position) as ; clicked => $on_play_pause_clicked (); } diff --git a/src/ui/playbar.vala b/src/ui/playbar.vala index a555a12..0b38644 100644 --- a/src/ui/playbar.vala +++ b/src/ui/playbar.vala @@ -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"; }