diff --git a/front/src/audio/queue.js b/front/src/audio/queue.js index 77fe6bf2bc89bf0f9fc114b52f7512f9ea19ef94..bde0bf863fc4b04f5fd73102659334c633683f07 100644 --- a/front/src/audio/queue.js +++ b/front/src/audio/queue.js @@ -116,7 +116,7 @@ class Queue { } } - append (track, index) { + append (track, index, skipPlay) { this.previousQueue = null index = index || this.tracks.length if (index > this.tracks.length - 1) { @@ -126,20 +126,32 @@ class Queue { // we insert the track at given position this.tracks.splice(index, 0, track) } - if (this.ended) { - logger.default.debug('Playing appended track') - this.play(this.currentIndex + 1) + if (!skipPlay) { + this.resumeQueue() } this.cache() } appendMany (tracks, index) { + logger.default.info('Appending many tracks to the queue', tracks.map(e => { return e.title })) 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) => { - self.append(t, index) + self.append(t, index, true) index += 1 }) + this.resumeQueue() + } + + resumeQueue () { + if (this.ended | this.errored) { + this.next() + } } populateFromRadio () { @@ -185,15 +197,24 @@ class Queue { } stop () { - this.audio.pause() - this.audio.destroyed() + if (this.audio.pause) { + this.audio.pause() + } + if (this.audio.destroyed) { + this.audio.destroyed() + } } play (index) { let self = this let currentIndex = index let currentTrack = this.tracks[index] + + if (this.audio.destroyed) { + logger.default.debug('Destroying previous audio...', index - 1) + this.audio.destroyed() + } + if (!currentTrack) { - logger.default.debug('No track at index', index) return } @@ -201,12 +222,13 @@ class Queue { this.currentTrack = currentTrack this.ended = false + this.errored = false let file = this.currentTrack.files[0] if (!file) { + this.errored = true return this.next() } let path = backend.absoluteUrl(file.path) - if (auth.user.authenticated) { // we need to send the token directly in url // so authentication can be checked by the backend @@ -215,10 +237,6 @@ class Queue { 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, { preload: true, autoplay: true, @@ -271,6 +289,7 @@ class Queue { next () { if (this.currentIndex < this.tracks.length - 1) { + logger.default.debug('Playing next track') this.play(this.currentIndex + 1) } } diff --git a/front/src/components/audio/track/Table.vue b/front/src/components/audio/track/Table.vue index 055c986d2fdf416d01215fa328ba59bea3a34c07..efb98e382804ecb2623d4f96f5e6b9935559052b 100644 --- a/front/src/components/audio/track/Table.vue +++ b/front/src/components/audio/track/Table.vue @@ -59,8 +59,8 @@ </div> <pre> export PRIVATE_TOKEN="{{ auth.getAuthToken ()}}" -<template v-for="track in tracks"> -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 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></template> </pre> </div> </div>