Now persist/restore queue/radio/player state automatically

This commit is contained in:
Eliot Berriot 2017-12-24 22:48:29 +01:00
parent ac13657863
commit 62a7d9091e
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
13 changed files with 111 additions and 70 deletions

View file

@ -22,7 +22,9 @@ import url from '@/utils/url'
export default {
props: {
track: {type: Object},
isCurrent: {type: Boolean, default: false}
isCurrent: {type: Boolean, default: false},
startTime: {type: Number, default: 0},
autoplay: {type: Boolean, default: false}
},
computed: {
...mapState({
@ -57,8 +59,11 @@ export default {
},
loaded: function () {
this.$store.commit('player/duration', this.$refs.audio.duration)
if (this.isCurrent) {
if (this.isCurrent && this.autoplay) {
this.$store.commit('player/duration', this.$refs.audio.duration)
if (this.startTime) {
this.setCurrentTime(this.startTime)
}
this.$store.commit('player/playing', true)
this.$refs.audio.play()
}
@ -72,8 +77,9 @@ export default {
if (this.looping === 1) {
this.setCurrentTime(0)
this.$refs.audio.play()
} else {
this.$store.dispatch('player/trackEnded', this.track)
}
this.$store.dispatch('player/trackEnded', this.track)
},
setCurrentTime (t) {
if (t < 0 | t > this.duration) {