Add repeat mode options to playlist #52

This commit is contained in:
Rafał Dzięgiel
2021-04-27 14:50:54 +02:00
parent de65eee106
commit fd2de8b9b6
2 changed files with 37 additions and 1 deletions

View File

@@ -560,7 +560,7 @@ class ClapperPlayer extends GstClapper.Clapper
debug(`end of stream: ${lastTrackId}`); debug(`end of stream: ${lastTrackId}`);
this.emitWs('end_of_stream', lastTrackId); this.emitWs('end_of_stream', lastTrackId);
if(this.playlistWidget.nextTrack()) if(this.playlistWidget._handleStreamEnded(player))
return; return;
if(settings.get_boolean('close-auto')) { if(settings.get_boolean('close-auto')) {

View File

@@ -1,5 +1,11 @@
const { Gdk, GLib, GObject, Gst, Gtk, Pango } = imports.gi; const { Gdk, GLib, GObject, Gst, Gtk, Pango } = imports.gi;
var RepeatMode = {
NONE: 0,
TRACK: 1,
PLAYLIST: 2,
};
var PlaylistWidget = GObject.registerClass( var PlaylistWidget = GObject.registerClass(
class ClapperPlaylistWidget extends Gtk.ListBox class ClapperPlaylistWidget extends Gtk.ListBox
{ {
@@ -9,6 +15,8 @@ class ClapperPlaylistWidget extends Gtk.ListBox
selection_mode: Gtk.SelectionMode.NONE, selection_mode: Gtk.SelectionMode.NONE,
}); });
this.activeRowId = -1; this.activeRowId = -1;
this.repeatMode = RepeatMode.NONE;
this.connect('row-activated', this._onRowActivated.bind(this)); this.connect('row-activated', this._onRowActivated.bind(this));
} }
@@ -88,6 +96,11 @@ class ClapperPlaylistWidget extends Gtk.ListBox
? this.activeRowId - 1 ? this.activeRowId - 1
: this.activeRowId + 1; : this.activeRowId + 1;
return this._changeActiveRow(rowId);
}
_changeActiveRow(rowId)
{
const row = this.get_row_at_index(rowId); const row = this.get_row_at_index(rowId);
if(!row) if(!row)
return false; return false;
@@ -110,6 +123,29 @@ class ClapperPlaylistWidget extends Gtk.ListBox
this.activeRowId = row.get_index(); this.activeRowId = row.get_index();
player.set_uri(row.uri); player.set_uri(row.uri);
} }
_handleStreamEnded(player)
{
/* Seek to beginning when repeating track
* or playlist with only one item */
if(
this.repeatMode === RepeatMode.TRACK
|| (this.repeatMode === RepeatMode.PLAYLIST
&& this.activeRowId === 0
&& !this.get_row_at_index(1))
) {
player.seek(0);
return true;
}
if(this.nextTrack())
return true;
if(this.repeatMode === RepeatMode.PLAYLIST)
return this._changeActiveRow(0);
return false;
}
}); });
let PlaylistItem = GObject.registerClass( let PlaylistItem = GObject.registerClass(