From 75a1d74962450be2b84bf21fbfb9e5e683c53ed7 Mon Sep 17 00:00:00 2001
From: heyarne <arne@schlueter.is>
Date: Thu, 8 Apr 2021 07:55:23 +0000
Subject: [PATCH] Stop all other tracks when loading a new track

---
 changes/changelog.d/1291.bugfix       |  1 +
 front/src/components/audio/Player.vue | 31 ++++++++++++---------------
 2 files changed, 15 insertions(+), 17 deletions(-)
 create mode 100644 changes/changelog.d/1291.bugfix

diff --git a/changes/changelog.d/1291.bugfix b/changes/changelog.d/1291.bugfix
new file mode 100644
index 0000000000..06cd0a7db6
--- /dev/null
+++ b/changes/changelog.d/1291.bugfix
@@ -0,0 +1 @@
+Fix tracks playing in the background without the ability to control them (#1213) (#1387)
diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue
index e8bbb8dd81..208ec00f5a 100644
--- a/front/src/components/audio/Player.vue
+++ b/front/src/components/audio/Player.vue
@@ -304,21 +304,15 @@ export default {
       toggleMute: "player/toggleMute",
     }),
     async getTrackData (trackData) {
-      let data = null
-      if (!trackData.uploads.length || trackData.uploads.length === 0) {
-        // we don't have upload informations for this track, we need to fetch it
-        await axios.get(`tracks/${trackData.id}/`).then((response) => {
-          data = response.data
-        }, error => {
-          data = null
-        })
-      } else {
-        return trackData
-      }
-      if (data === null) {
-        return
-      }
-      return data
+      // use previously fetched trackData
+      if (trackData.uploads.length) return trackData
+
+      // we don't have any information for this track, we need to fetch it
+      return axios.get(`tracks/${trackData.id}/`)
+                  .then(
+                    response => response.data,
+                    err => null
+                  )
     },
     shuffle() {
       let disabled = this.queue.tracks.length === 0
@@ -611,8 +605,11 @@ export default {
     async loadSound (newValue, oldValue) {
       let trackData = newValue
       let oldSound = this.currentSound
+      // stop all other sounds!
+      // we do this here (before the track has loaded) to get a predictable
+      // song order.
+      Howler.stop()
       if (oldSound && trackData !== oldValue) {
-        oldSound.stop(this.soundId)
         this.soundId = null
       }
       if (!trackData) {
@@ -620,7 +617,7 @@ export default {
       }
       if (!this.isShuffling && trackData != oldValue) {
         trackData = await this.getTrackData(trackData)
-        if (trackData === null) {
+        if (trackData == null) {
           this.handleError({})
         }
         this.currentSound = this.getSound(trackData)
-- 
GitLab