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

Merge branch 'player-enhancements' into 'develop'

Player enhancements

See merge request funkwhale/funkwhale!755
parents 3b06cd25 aad2a505
No related branches found
No related tags found
No related merge requests found
...@@ -323,9 +323,7 @@ def handle_serve(upload, user, format=None, max_bitrate=None): ...@@ -323,9 +323,7 @@ def handle_serve(upload, user, format=None, max_bitrate=None):
mt = f.mimetype mt = f.mimetype
if should_transcode(f, format, max_bitrate=max_bitrate): if should_transcode(f, format, max_bitrate=max_bitrate):
transcoded_version = upload.get_transcoded_version( transcoded_version = f.get_transcoded_version(format, max_bitrate=max_bitrate)
format, max_bitrate=max_bitrate
)
transcoded_version.accessed_date = now transcoded_version.accessed_date = now
transcoded_version.save(update_fields=["accessed_date"]) transcoded_version.save(update_fields=["accessed_date"])
f = transcoded_version f = transcoded_version
......
...@@ -254,11 +254,17 @@ export default { ...@@ -254,11 +254,17 @@ export default {
maxPreloaded: 3, maxPreloaded: 3,
preloadDelay: 15, preloadDelay: 15,
soundsCache: [], soundsCache: [],
soundId: null soundId: null,
playTimeout: null,
nextTrackPreloaded: false
} }
}, },
mounted() { 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 Howler.unload() // clear existing cache, if any
this.nextTrackPreloaded = false
// we trigger the watcher explicitely it does not work otherwise // we trigger the watcher explicitely it does not work otherwise
this.sliderVolume = this.volume this.sliderVolume = this.volume
// this is needed to unlock audio playing under some browsers, // this is needed to unlock audio playing under some browsers,
...@@ -273,10 +279,12 @@ export default { ...@@ -273,10 +279,12 @@ export default {
this.getSound(this.currentTrack) this.getSound(this.currentTrack)
} }
}, },
destroyed() { beforeDestroy () {
this.dummyAudio.unload() this.dummyAudio.unload()
this.observeProgress(false) this.observeProgress(false)
}, },
destroyed() {
},
methods: { methods: {
...mapActions({ ...mapActions({
togglePlay: "player/togglePlay", togglePlay: "player/togglePlay",
...@@ -391,6 +399,7 @@ export default { ...@@ -391,6 +399,7 @@ export default {
self.$store.commit('player/duration', this.duration()) self.$store.commit('player/duration', this.duration())
}, },
onloaderror: function (sound, error) { onloaderror: function (sound, error) {
self.removeFromCache(this)
if (this != self.currentSound) { if (this != self.currentSound) {
return return
} }
...@@ -471,8 +480,9 @@ export default { ...@@ -471,8 +480,9 @@ export default {
this.$store.dispatch('player/updateProgress', t) this.$store.dispatch('player/updateProgress', t)
this.updateBuffer(this.currentSound._sounds[0]._node) this.updateBuffer(this.currentSound._sounds[0]._node)
let toPreload = this.$store.state.queue.tracks[this.currentIndex + 1] 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.getSound(toPreload)
this.nextTrackPreloaded = true
} }
} }
}, },
...@@ -544,6 +554,17 @@ export default { ...@@ -544,6 +554,17 @@ export default {
}) })
this.soundsCache = _.reverse(toKeep) 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) { async loadSound (newValue, oldValue) {
let trackData = newValue let trackData = newValue
let oldSound = this.currentSound let oldSound = this.currentSound
...@@ -563,7 +584,9 @@ export default { ...@@ -563,7 +584,9 @@ export default {
this.$store.commit('player/isLoadingAudio', true) this.$store.commit('player/isLoadingAudio', true)
if (this.playing) { if (this.playing) {
this.soundId = this.currentSound.play() this.soundId = this.currentSound.play()
this.$store.commit('player/errored', false)
this.$store.commit('player/playing', true) this.$store.commit('player/playing', true)
this.$store.dispatch('player/updateProgress', 0)
this.observeProgress(true) this.observeProgress(true)
} }
} }
...@@ -659,10 +682,22 @@ export default { ...@@ -659,10 +682,22 @@ export default {
watch: { watch: {
currentTrack: { currentTrack: {
async handler (newValue, oldValue) { async handler (newValue, oldValue) {
await this.loadSound(newValue, oldValue) if (newValue === oldValue) {
if (!newValue || !newValue.album.cover) { return
this.ambiantColors = this.defaultAmbiantColors }
this.nextTrackPreloaded = false
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 immediate: false
}, },
......
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