From dac8d6e05e2508e7de9f3ae6fe14990c1a4e8387 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Tue, 27 Feb 2018 21:27:53 +0100
Subject: [PATCH] Fix #86: skip to next track properly on 40X errors

---
 changes/changelog.d/86.bugfix        |  1 +
 front/src/components/audio/Track.vue | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 changes/changelog.d/86.bugfix

diff --git a/changes/changelog.d/86.bugfix b/changes/changelog.d/86.bugfix
new file mode 100644
index 000000000..c02a1997c
--- /dev/null
+++ b/changes/changelog.d/86.bugfix
@@ -0,0 +1 @@
+skip to next track properly on 40X errors (#86)
diff --git a/front/src/components/audio/Track.vue b/front/src/components/audio/Track.vue
index d8dcaff9b..e2b613095 100644
--- a/front/src/components/audio/Track.vue
+++ b/front/src/components/audio/Track.vue
@@ -7,7 +7,11 @@
     @timeupdate="updateProgress"
     @ended="ended"
     preload>
-    <source v-for="src in srcs" :src="src.url" :type="src.type">
+    <source
+      @error="sourceErrored"
+      v-for="src in srcs"
+      src="src.url"
+      :type="src.type">
   </audio>
 </template>
 
@@ -25,6 +29,11 @@ export default {
     startTime: {type: Number, default: 0},
     autoplay: {type: Boolean, default: false}
   },
+  data () {
+    return {
+      sourceErrors: 0
+    }
+  },
   computed: {
     ...mapState({
       playing: state => state.player.playing,
@@ -65,6 +74,13 @@ export default {
     errored: function () {
       this.$store.dispatch('player/trackErrored')
     },
+    sourceErrored: function () {
+      this.sourceErrors += 1
+      if (this.sourceErrors >= this.srcs.length) {
+        // all sources failed
+        this.errored()
+      }
+    },
     updateDuration: function (e) {
       this.$store.commit('player/duration', this.$refs.audio.duration)
     },
-- 
GitLab