mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Add repeat mode options to playlist #52
This commit is contained in:
@@ -560,7 +560,7 @@ class ClapperPlayer extends GstClapper.Clapper
|
||||
debug(`end of stream: ${lastTrackId}`);
|
||||
this.emitWs('end_of_stream', lastTrackId);
|
||||
|
||||
if(this.playlistWidget.nextTrack())
|
||||
if(this.playlistWidget._handleStreamEnded(player))
|
||||
return;
|
||||
|
||||
if(settings.get_boolean('close-auto')) {
|
||||
|
@@ -1,5 +1,11 @@
|
||||
const { Gdk, GLib, GObject, Gst, Gtk, Pango } = imports.gi;
|
||||
|
||||
var RepeatMode = {
|
||||
NONE: 0,
|
||||
TRACK: 1,
|
||||
PLAYLIST: 2,
|
||||
};
|
||||
|
||||
var PlaylistWidget = GObject.registerClass(
|
||||
class ClapperPlaylistWidget extends Gtk.ListBox
|
||||
{
|
||||
@@ -9,6 +15,8 @@ class ClapperPlaylistWidget extends Gtk.ListBox
|
||||
selection_mode: Gtk.SelectionMode.NONE,
|
||||
});
|
||||
this.activeRowId = -1;
|
||||
this.repeatMode = RepeatMode.NONE;
|
||||
|
||||
this.connect('row-activated', this._onRowActivated.bind(this));
|
||||
}
|
||||
|
||||
@@ -88,6 +96,11 @@ class ClapperPlaylistWidget extends Gtk.ListBox
|
||||
? this.activeRowId - 1
|
||||
: this.activeRowId + 1;
|
||||
|
||||
return this._changeActiveRow(rowId);
|
||||
}
|
||||
|
||||
_changeActiveRow(rowId)
|
||||
{
|
||||
const row = this.get_row_at_index(rowId);
|
||||
if(!row)
|
||||
return false;
|
||||
@@ -110,6 +123,29 @@ class ClapperPlaylistWidget extends Gtk.ListBox
|
||||
this.activeRowId = row.get_index();
|
||||
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(
|
||||
|
Reference in New Issue
Block a user