Fixed #46: better handling of HTTP errors when fetching audio file

This commit is contained in:
Eliot Berriot 2017-12-15 22:03:15 +01:00
parent a4e31cdb9d
commit 13eddbfc21
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
3 changed files with 12 additions and 3 deletions

View File

@ -6,6 +6,7 @@ Changelog
------------------ ------------------
- Import: can now specify search template when querying import sources (#45) - Import: can now specify search template when querying import sources (#45)
- Player: better handling of errors when fetching the audio file (#46)
0.2.4 (2017-12-14) 0.2.4 (2017-12-14)

View File

@ -26,6 +26,7 @@ class Audio {
if (options.onEnded) { if (options.onEnded) {
this.onEnded = options.onEnded this.onEnded = options.onEnded
} }
this.onError = options.onError
this.state = { this.state = {
preload: preload, preload: preload,
@ -60,8 +61,12 @@ class Audio {
init (src, options = {}) { init (src, options = {}) {
if (!src) throw Error('src must be required') if (!src) throw Error('src must be required')
this.state.startLoad = true this.state.startLoad = true
if (this.state.tried === this.state.try) { if (this.state.tried >= this.state.try) {
this.state.failed = true this.state.failed = true
logger.default.error('Cannot fetch audio', src)
if (this.onError) {
this.onError(src)
}
return return
} }
this.$Audio = new window.Audio(src) this.$Audio = new window.Audio(src)

View File

@ -140,7 +140,6 @@ class Queue {
} else { } else {
index = index || this.tracks.length index = index || this.tracks.length
} }
console.log('INDEEEEEX', index)
tracks.forEach((t) => { tracks.forEach((t) => {
self.append(t, index, true) self.append(t, index, true)
index += 1 index += 1
@ -243,7 +242,11 @@ class Queue {
rate: 1, rate: 1,
loop: false, loop: false,
volume: this.state.volume, volume: this.state.volume,
onEnded: this.handleAudioEnded.bind(this) onEnded: this.handleAudioEnded.bind(this),
onError: function (src) {
self.errored = true
self.next()
}
}) })
this.audio = audio this.audio = audio
audio.updateHook('playState', function (e) { audio.updateHook('playState', function (e) {