Skip to content
Snippets Groups Projects
Commit 6274031f authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch 'feature/46-player-error-404' into 'develop'

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

Closes #46

See merge request funkwhale/funkwhale!25
parents a4e31cdb 13eddbfc
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ Changelog ...@@ -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)
......
...@@ -26,6 +26,7 @@ class Audio { ...@@ -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 { ...@@ -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)
......
...@@ -140,7 +140,6 @@ class Queue { ...@@ -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 { ...@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment