[gnome-music] working logic for repeat
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] working logic for repeat
- Date: Thu, 25 Apr 2013 11:24:56 +0000 (UTC)
commit 786eba64060576477e6f88fd4c93626a8154271e
Author: Guillaume Quintard <guillaume quintard gmail com>
Date: Thu Apr 25 03:07:07 2013 +0200
working logic for repeat
src/player.js | 67 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 53 insertions(+), 14 deletions(-)
---
diff --git a/src/player.js b/src/player.js
index c36bccb..604ba99 100644
--- a/src/player.js
+++ b/src/player.js
@@ -34,6 +34,12 @@ const AlbumArtCache = imports.albumArtCache;
const ART_SIZE = 64;
+const RepeatType = {
+ NONE: 0,
+ SONG: 1,
+ ALL: 2
+}
+
const PlayPauseButton = new Lang.Class({
Name: "PlayPauseButton",
Extends: Gtk.ToggleButton,
@@ -84,6 +90,7 @@ const Player = new Lang.Class({
this.playlist_id = null;
this.playlist_field = null;
this.currentTrack = null;
+ this.repeat = RepeatType.NONE;
this.cache = AlbumArtCache.AlbumArtCache.getDefault();
Gst.init(null, 0);
@@ -179,28 +186,60 @@ const Player = new Lang.Class({
},
playNext: function () {
- if (this.currentTrack)
- this.prevTrack = this.currentTrack.copy()
- if (!this.playlist || !this.currentTrack || !this.playlist.iter_next(this.currentTrack)){
- if (this.prevTrack) {
- this.currentTrack = this.prevTrack.copy();
- } else {
- this.currentTrack = null;
- }
+ // don't do anything if we don't have the basics
+ if (!this.playlist || !this.currentTrack)
+ return;
+ let savedTrack;
+ // if we are in repeat dong mode, just play the song again
+ // other, save the node
+ if (RepeatType.SONG == this.repeat){
+ this.stop();
+ this.play();
return;
+ } else
+ savedTrack = this.currentTrack.copy()
+
+ // if we were able to just to the next iter, play it
+ // otherwise...
+ if (!this.playlist.iter_next(this.currentTrack)){
+ // ... if all repeat mode is activated, loop around the listStore
+ // if not, restore the saved node and don't play anything
+ if (RepeatType.ALL== this.repeat)
+ this.currentTrack = this.playlist.get_iter_first()[1];
+ else {
+ this.currentTrack = savedTrack;
+ return;
+ }
}
this.stop();
this.play();
},
playPrevious: function () {
- if (!this.playlist || !this.currentTrack || !this.playlist.iter_previous(this.currentTrack)){
- if (!this.playlist) {
- this.currentTrack = null;
- } else {
- this.currentTrack = this.playlist.get_iter_first()[1];
+ if (!this.playlist || !this.currentTrack)
+ return;
+ let savedTrack;
+ if (RepeatType.SONG == this.repeat){
+ this.stop();
+ this.play();
+ return;
+ } else
+ savedTrack = this.currentTrack.copy()
+
+ if (!this.playlist.iter_previous(this.currentTrack)){
+ if (RepeatType.ALL== this.repeat){
+ //FIXME there has to be a better way
+ let index = 0;
+ let iter = this.playlist.get_iter_first()[1];
+ while (this.playlist.iter_next(iter))
+ index++;
+ this.currentTrack = this.playlist.get_iter_from_string(index.toString())[1];
+ }
+ else {
+ this.currentTrack = savedTrack;
+ return;
}
- return;}
+ }
this.stop();
this.play();
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]