From 2c92825a089531d682ab26e268c61621b59f9f32 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 7 May 2019 11:39:37 +0200 Subject: [PATCH 1/6] Removed errored sounds from cache --- front/src/components/audio/Player.vue | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index d3a3decae..0c451bdac 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -391,6 +391,7 @@ export default { self.$store.commit('player/duration', this.duration()) }, onloaderror: function (sound, error) { + self.removeFromCache(this) if (this != self.currentSound) { return } @@ -544,6 +545,17 @@ export default { }) this.soundsCache = _.reverse(toKeep) }, + removeFromCache (sound) { + let toKeep = [] + this.soundsCache.forEach((e) => { + if (e.sound === sound) { + e.sound.unload() + } else { + toKeep.push(e) + } + }) + this.soundsCache = toKeep + }, async loadSound (newValue, oldValue) { let trackData = newValue let oldSound = this.currentSound From bc87674b34fc2bcc5bc6a7ab756b1baf373b293f Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 7 May 2019 11:47:53 +0200 Subject: [PATCH 2/6] Fixed error not hidden when playing next track --- front/src/components/audio/Player.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 0c451bdac..2086c0d41 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -575,6 +575,7 @@ export default { this.$store.commit('player/isLoadingAudio', true) if (this.playing) { this.soundId = this.currentSound.play() + this.$store.commit('player/errored', false) this.$store.commit('player/playing', true) this.observeProgress(true) } From 58195cd4d1fa2fd5395da8e988f906a09d063a62 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 7 May 2019 11:59:41 +0200 Subject: [PATCH 3/6] Added small timeout before playback to avoid loading lots of tracks when skipping through the queue --- front/src/components/audio/Player.vue | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 2086c0d41..81bdb91d2 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -254,7 +254,8 @@ export default { maxPreloaded: 3, preloadDelay: 15, soundsCache: [], - soundId: null + soundId: null, + playTimeout: null } }, mounted() { @@ -577,6 +578,7 @@ export default { this.soundId = this.currentSound.play() this.$store.commit('player/errored', false) this.$store.commit('player/playing', true) + this.$store.dispatch('player/updateProgress', 0) this.observeProgress(true) } } @@ -672,10 +674,18 @@ export default { watch: { currentTrack: { async handler (newValue, oldValue) { - await this.loadSound(newValue, oldValue) - if (!newValue || !newValue.album.cover) { - this.ambiantColors = this.defaultAmbiantColors + clearTimeout(this.playTimeout) + let self = this + if (this.currentSound) { + this.currentSound.pause() } + this.$store.commit("player/isLoadingAudio", true) + this.playTimeout = setTimeout(async () => { + await self.loadSound(newValue, oldValue) + if (!newValue || !newValue.album.cover) { + self.ambiantColors = self.defaultAmbiantColors + } + }, 500); }, immediate: false }, From 2cdf26b028ddf29f926e01b2d68df468d9dcc2e7 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 7 May 2019 12:05:18 +0200 Subject: [PATCH 4/6] Fixed small issues with queue --- front/src/components/audio/Player.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 81bdb91d2..0562b90a0 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -674,6 +674,9 @@ export default { watch: { currentTrack: { async handler (newValue, oldValue) { + if (newValue === oldValue) { + return + } clearTimeout(this.playTimeout) let self = this if (this.currentSound) { From 9671db0229a1108c9d2b0596e0b3d3dcd86a90d1 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 7 May 2019 12:32:41 +0200 Subject: [PATCH 5/6] Fixed chained preloading of tracks when remote answers with error --- front/src/components/audio/Player.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 0562b90a0..0ad8fe7c6 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -255,11 +255,16 @@ export default { preloadDelay: 15, soundsCache: [], soundId: null, - playTimeout: null + playTimeout: null, + nextTrackPreloaded: false } }, mounted() { + this.$store.dispatch('player/updateProgress', 0) + this.$store.commit('player/playing', false) + this.$store.commit("player/isLoadingAudio", false) Howler.unload() // clear existing cache, if any + this.nextTrackPreloaded = false // we trigger the watcher explicitely it does not work otherwise this.sliderVolume = this.volume // this is needed to unlock audio playing under some browsers, @@ -274,10 +279,12 @@ export default { this.getSound(this.currentTrack) } }, - destroyed() { + beforeDestroy () { this.dummyAudio.unload() this.observeProgress(false) }, + destroyed() { + }, methods: { ...mapActions({ togglePlay: "player/togglePlay", @@ -473,8 +480,9 @@ export default { this.$store.dispatch('player/updateProgress', t) this.updateBuffer(this.currentSound._sounds[0]._node) let toPreload = this.$store.state.queue.tracks[this.currentIndex + 1] - if (toPreload && !this.getSoundFromCache(toPreload) && (t > this.preloadDelay || d - t < 30)) { + if (!this.nextTrackPreloaded && toPreload && !this.getSoundFromCache(toPreload) && (t > this.preloadDelay || d - t < 30)) { this.getSound(toPreload) + this.nextTrackPreloaded = true } } }, @@ -677,6 +685,7 @@ export default { if (newValue === oldValue) { return } + this.nextTrackPreloaded = false clearTimeout(this.playTimeout) let self = this if (this.currentSound) { From aad2a50536d61c5f2780baa45d82361dd16c388e Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 7 May 2019 12:32:51 +0200 Subject: [PATCH 6/6] Fixed issue when transcoding from federation --- api/funkwhale_api/music/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index 37416216b..20e173d83 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -323,9 +323,7 @@ def handle_serve(upload, user, format=None, max_bitrate=None): mt = f.mimetype if should_transcode(f, format, max_bitrate=max_bitrate): - transcoded_version = upload.get_transcoded_version( - format, max_bitrate=max_bitrate - ) + transcoded_version = f.get_transcoded_version(format, max_bitrate=max_bitrate) transcoded_version.accessed_date = now transcoded_version.save(update_fields=["accessed_date"]) f = transcoded_version