Fixed #42: player should be more resilient in case of play error
This commit is contained in:
parent
516f6e6d38
commit
4954c50a70
|
@ -116,7 +116,7 @@ class Queue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
append (track, index) {
|
append (track, index, skipPlay) {
|
||||||
this.previousQueue = null
|
this.previousQueue = null
|
||||||
index = index || this.tracks.length
|
index = index || this.tracks.length
|
||||||
if (index > this.tracks.length - 1) {
|
if (index > this.tracks.length - 1) {
|
||||||
|
@ -126,20 +126,32 @@ class Queue {
|
||||||
// we insert the track at given position
|
// we insert the track at given position
|
||||||
this.tracks.splice(index, 0, track)
|
this.tracks.splice(index, 0, track)
|
||||||
}
|
}
|
||||||
if (this.ended) {
|
if (!skipPlay) {
|
||||||
logger.default.debug('Playing appended track')
|
this.resumeQueue()
|
||||||
this.play(this.currentIndex + 1)
|
|
||||||
}
|
}
|
||||||
this.cache()
|
this.cache()
|
||||||
}
|
}
|
||||||
|
|
||||||
appendMany (tracks, index) {
|
appendMany (tracks, index) {
|
||||||
|
logger.default.info('Appending many tracks to the queue', tracks.map(e => { return e.title }))
|
||||||
let self = this
|
let self = this
|
||||||
index = index || this.tracks.length - 1
|
if (this.tracks.length === 0) {
|
||||||
|
index = 0
|
||||||
|
} else {
|
||||||
|
index = index || this.tracks.length
|
||||||
|
}
|
||||||
|
console.log('INDEEEEEX', index)
|
||||||
tracks.forEach((t) => {
|
tracks.forEach((t) => {
|
||||||
self.append(t, index)
|
self.append(t, index, true)
|
||||||
index += 1
|
index += 1
|
||||||
})
|
})
|
||||||
|
this.resumeQueue()
|
||||||
|
}
|
||||||
|
|
||||||
|
resumeQueue () {
|
||||||
|
if (this.ended | this.errored) {
|
||||||
|
this.next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
populateFromRadio () {
|
populateFromRadio () {
|
||||||
|
@ -185,15 +197,24 @@ class Queue {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop () {
|
||||||
this.audio.pause()
|
if (this.audio.pause) {
|
||||||
this.audio.destroyed()
|
this.audio.pause()
|
||||||
|
}
|
||||||
|
if (this.audio.destroyed) {
|
||||||
|
this.audio.destroyed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
play (index) {
|
play (index) {
|
||||||
let self = this
|
let self = this
|
||||||
let currentIndex = index
|
let currentIndex = index
|
||||||
let currentTrack = this.tracks[index]
|
let currentTrack = this.tracks[index]
|
||||||
|
|
||||||
|
if (this.audio.destroyed) {
|
||||||
|
logger.default.debug('Destroying previous audio...', index - 1)
|
||||||
|
this.audio.destroyed()
|
||||||
|
}
|
||||||
|
|
||||||
if (!currentTrack) {
|
if (!currentTrack) {
|
||||||
logger.default.debug('No track at index', index)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,12 +222,13 @@ class Queue {
|
||||||
this.currentTrack = currentTrack
|
this.currentTrack = currentTrack
|
||||||
|
|
||||||
this.ended = false
|
this.ended = false
|
||||||
|
this.errored = false
|
||||||
let file = this.currentTrack.files[0]
|
let file = this.currentTrack.files[0]
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
this.errored = true
|
||||||
return this.next()
|
return this.next()
|
||||||
}
|
}
|
||||||
let path = backend.absoluteUrl(file.path)
|
let path = backend.absoluteUrl(file.path)
|
||||||
|
|
||||||
if (auth.user.authenticated) {
|
if (auth.user.authenticated) {
|
||||||
// we need to send the token directly in url
|
// we need to send the token directly in url
|
||||||
// so authentication can be checked by the backend
|
// so authentication can be checked by the backend
|
||||||
|
@ -215,10 +237,6 @@ class Queue {
|
||||||
path = url.updateQueryString(path, 'jwt', auth.getAuthToken())
|
path = url.updateQueryString(path, 'jwt', auth.getAuthToken())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.audio.destroyed) {
|
|
||||||
logger.default.debug('Destroying previous audio...', index - 1)
|
|
||||||
this.audio.destroyed()
|
|
||||||
}
|
|
||||||
let audio = new Audio(path, {
|
let audio = new Audio(path, {
|
||||||
preload: true,
|
preload: true,
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
|
@ -271,6 +289,7 @@ class Queue {
|
||||||
|
|
||||||
next () {
|
next () {
|
||||||
if (this.currentIndex < this.tracks.length - 1) {
|
if (this.currentIndex < this.tracks.length - 1) {
|
||||||
|
logger.default.debug('Playing next track')
|
||||||
this.play(this.currentIndex + 1)
|
this.play(this.currentIndex + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,8 @@
|
||||||
</div>
|
</div>
|
||||||
<pre>
|
<pre>
|
||||||
export PRIVATE_TOKEN="{{ auth.getAuthToken ()}}"
|
export PRIVATE_TOKEN="{{ auth.getAuthToken ()}}"
|
||||||
<template v-for="track in tracks">
|
<template v-for="track in tracks"><template v-if="track.files.length > 0">
|
||||||
curl -G -o "{{ track.files[0].filename }}" <template v-if="auth.user.authenticated">--header "Authorization: JWT $PRIVATE_TOKEN"</template> "{{ backend.absoluteUrl(track.files[0].path) }}"</template>
|
curl -G -o "{{ track.files[0].filename }}" <template v-if="auth.user.authenticated">--header "Authorization: JWT $PRIVATE_TOKEN"</template> "{{ backend.absoluteUrl(track.files[0].path) }}"</template></template>
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue