mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 23:32:04 +02:00
Add playlist shuffle repeat mode #52
This commit is contained in:
@@ -7,12 +7,14 @@ var RepeatMode = {
|
||||
NONE: 0,
|
||||
TRACK: 1,
|
||||
PLAYLIST: 2,
|
||||
SHUFFLE: 3,
|
||||
};
|
||||
|
||||
const repeatIcons = [
|
||||
'media-playlist-consecutive-symbolic',
|
||||
'media-playlist-repeat-song-symbolic',
|
||||
'media-playlist-repeat-symbolic',
|
||||
'media-playlist-shuffle-symbolic',
|
||||
];
|
||||
|
||||
var PlaylistWidget = GObject.registerClass(
|
||||
@@ -176,6 +178,36 @@ class ClapperPlaylistWidget extends Gtk.ListBox
|
||||
return true;
|
||||
}
|
||||
|
||||
if(this.repeatMode === RepeatMode.SHUFFLE) {
|
||||
const playlistIds = [];
|
||||
let index = 0;
|
||||
|
||||
debug('selecting random playlist item');
|
||||
|
||||
while(this.get_row_at_index(index)) {
|
||||
/* We prefer to not repeat the same track */
|
||||
if(index !== this.activeRowId)
|
||||
playlistIds.push(index);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
if(playlistIds.length) {
|
||||
const randomId = playlistIds[
|
||||
Math.floor(Math.random() * playlistIds.length)
|
||||
];
|
||||
debug(`selected random playlist item: ${randomId}`);
|
||||
|
||||
return this.changeActiveRow(randomId);
|
||||
}
|
||||
else {
|
||||
debug('only one playlist item, playing again');
|
||||
|
||||
player.seek(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.nextTrack())
|
||||
return true;
|
||||
|
||||
|
Reference in New Issue
Block a user