mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 12:59:30 +02:00
Added looping controls
This commit is contained in:
parent
fcf75260e0
commit
f6c939db4c
3 changed files with 103 additions and 14 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue