diff --git a/CHANGELOG b/CHANGELOG index 87c584200cd5fc3dfc50c8468ceaa4ddf2cf24d9..3b31937fc6bc63eb69c18af9082e0f0f9c8a9372 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Changelog ------------------ - 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) diff --git a/front/src/audio/index.js b/front/src/audio/index.js index 7750ee500a47eb9d4074645642a3e121f8885b12..4896b83b0f895c8bca9269aebf9141d16ab53087 100644 --- a/front/src/audio/index.js +++ b/front/src/audio/index.js @@ -26,6 +26,7 @@ class Audio { if (options.onEnded) { this.onEnded = options.onEnded } + this.onError = options.onError this.state = { preload: preload, @@ -60,8 +61,12 @@ class Audio { init (src, options = {}) { if (!src) throw Error('src must be required') this.state.startLoad = true - if (this.state.tried === this.state.try) { + if (this.state.tried >= this.state.try) { this.state.failed = true + logger.default.error('Cannot fetch audio', src) + if (this.onError) { + this.onError(src) + } return } this.$Audio = new window.Audio(src) diff --git a/front/src/audio/queue.js b/front/src/audio/queue.js index bde0bf863fc4b04f5fd73102659334c633683f07..8c69638e80ceb46adfdd182010ced55898b6850f 100644 --- a/front/src/audio/queue.js +++ b/front/src/audio/queue.js @@ -140,7 +140,6 @@ class Queue { } else { index = index || this.tracks.length } - console.log('INDEEEEEX', index) tracks.forEach((t) => { self.append(t, index, true) index += 1 @@ -243,7 +242,11 @@ class Queue { rate: 1, loop: false, 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 audio.updateHook('playState', function (e) {