diff --git a/CHANGELOG b/CHANGELOG index d9d896035..2f6cbe48b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ Changelog - Shortcuts: can now use the ``f`` shortcut to toggle the currently playing track as a favorite (#53) - Shortcuts: avoid collisions between shortcuts by using the exact modifier (#53) +- Player: Added looping controls and shortcuts (#52) 0.2.6 (2017-12-15) diff --git a/front/src/audio/queue.js b/front/src/audio/queue.js index 8c69638e8..bb3f0f905 100644 --- a/front/src/audio/queue.js +++ b/front/src/audio/queue.js @@ -17,6 +17,7 @@ class Queue { this.currentTrack = null this.ended = true this.state = { + looping: 0, // 0 -> no, 1 -> on track, 2 -> on queue volume: cache.get('volume', 0.5) } this.audio = { @@ -267,12 +268,22 @@ class Queue { handleAudioEnded (e) { this.recordListen(this.currentTrack) + if (this.state.looping === 1) { + // we loop on the same track + logger.default.info('Looping on the same track') + return this.play(this.currentIndex) + } if (this.currentIndex < this.tracks.length - 1) { logger.default.info('Audio track ended, playing next one') - this.next() + return this.next() } else { logger.default.info('We reached the end of the queue') - this.ended = true + if (this.state.looping === 2) { + logger.default.info('Going back to the beginning of the queue') + return this.play(0) + } else { + this.ended = true + } } } @@ -297,6 +308,14 @@ class Queue { } } + toggleLooping () { + if (this.state.looping > 1) { + this.state.looping = 0 + } else { + this.state.looping += 1 + } + } + } let queue = new Queue() diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index aff3e65bd..8cdb261c5 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -39,21 +39,71 @@ -