diff --git a/CHANGELOG b/CHANGELOG index d9d896035..aa2b67dfa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,8 @@ 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) +- Player: Added shuffling 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..4273fb9a6 100644 --- a/front/src/audio/queue.js +++ b/front/src/audio/queue.js @@ -1,10 +1,12 @@ +import Vue from 'vue' +import _ from 'lodash' + import logger from '@/logging' import cache from '@/cache' import config from '@/config' import Audio from '@/audio' import backend from '@/audio/backend' import radios from '@/radios' -import Vue from 'vue' import url from '@/utils/url' import auth from '@/auth' @@ -17,6 +19,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 +270,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 +310,21 @@ class Queue { } } + toggleLooping () { + if (this.state.looping > 1) { + this.state.looping = 0 + } else { + this.state.looping += 1 + } + } + + shuffle () { + let tracks = this.tracks + let shuffled = _.shuffle(tracks) + this.clean() + this.appendMany(shuffled) + } + } let queue = new Queue() diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index aff3e65bd..c862660ad 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -39,21 +39,78 @@ -
-
- +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
-
- - - - +
+ + + 1 + + +
-
- +
+ +
+
+
+
@@ -187,14 +246,32 @@ export default { .volume-control { position: relative; .icon { - margin: 0; + // margin: 0; } [type="range"] { - max-width: 75%; + max-width: 100%; position: absolute; bottom: 5px; left: 10%; cursor: pointer; + display: none; + } + &:hover { + [type="range"] { + display: block; + } + } +} + +.looping.control { + i { + position: relative; + } + .label { + position: absolute; + font-size: 0.7rem; + bottom: -0.7rem; + right: -0.7rem; } } .ui.feed.icon {