Added looping controls

This commit is contained in:
Eliot Berriot 2017-12-17 17:07:15 +01:00
parent fcf75260e0
commit f6c939db4c
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
3 changed files with 103 additions and 14 deletions

View file

@ -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()