Reset player position before playing previous track

This commit is contained in:
Bat 2018-03-31 14:14:58 +01:00
parent 876aee19cf
commit 6b8dc1b53c
4 changed files with 15 additions and 18 deletions

View File

@ -58,9 +58,8 @@
<div class="two wide column controls ui grid"> <div class="two wide column controls ui grid">
<div <div
title="Previous track" title="Previous track"
class="two wide column control" class="two wide column control">
:disabled="!hasPrevious"> <i @click="previous" class="ui step backward big icon"></i>
<i @click="previous" :class="['ui', {'disabled': !hasPrevious}, 'step', 'backward', 'big', 'icon']" ></i>
</div> </div>
<div <div
v-if="!playing" v-if="!playing"
@ -205,7 +204,6 @@ export default {
...mapGetters({ ...mapGetters({
currentTrack: 'queue/currentTrack', currentTrack: 'queue/currentTrack',
hasNext: 'queue/hasNext', hasNext: 'queue/hasNext',
hasPrevious: 'queue/hasPrevious',
durationFormatted: 'player/durationFormatted', durationFormatted: 'player/durationFormatted',
currentTimeFormatted: 'player/currentTimeFormatted', currentTimeFormatted: 'player/currentTimeFormatted',
progress: 'player/progress' progress: 'player/progress'

View File

@ -31,7 +31,8 @@ export default {
}, },
data () { data () {
return { return {
sourceErrors: 0 sourceErrors: 0,
isUpdatingTime: false
} }
}, },
computed: { computed: {
@ -99,6 +100,7 @@ export default {
} }
}, },
updateProgress: _.throttle(function () { updateProgress: _.throttle(function () {
this.isUpdatingTime = true
if (this.$refs.audio) { if (this.$refs.audio) {
this.$store.dispatch('player/updateProgress', this.$refs.audio.currentTime) this.$store.dispatch('player/updateProgress', this.$refs.audio.currentTime)
} }
@ -130,6 +132,12 @@ export default {
}, },
volume: function (newValue) { volume: function (newValue) {
this.$refs.audio.volume = newValue this.$refs.audio.volume = newValue
},
currentTime (newValue) {
if (!this.isUpdatingTime) {
this.setCurrentTime(newValue)
}
this.isUpdatingTime = false
} }
} }
} }

View File

@ -48,9 +48,6 @@ export default {
}, },
hasNext: state => { hasNext: state => {
return state.currentIndex < state.tracks.length - 1 return state.currentIndex < state.tracks.length - 1
},
hasPrevious: state => {
return state.currentIndex > 0
} }
}, },
actions: { actions: {
@ -103,9 +100,11 @@ export default {
dispatch('next') dispatch('next')
} }
}, },
previous ({state, dispatch}) { previous ({state, dispatch, rootState}) {
if (state.currentIndex > 0) { if (state.currentIndex > 0 && rootState.player.currentTime < 3) {
dispatch('currentIndex', state.currentIndex - 1) dispatch('currentIndex', state.currentIndex - 1)
} else {
dispatch('currentIndex', state.currentIndex)
} }
}, },
next ({state, dispatch, commit, rootState}) { next ({state, dispatch, commit, rootState}) {

View File

@ -81,14 +81,6 @@ describe('store/queue', () => {
const state = { tracks: [1, 2, 3], currentIndex: 2 } const state = { tracks: [1, 2, 3], currentIndex: 2 }
expect(store.getters['hasNext'](state)).to.equal(false) expect(store.getters['hasNext'](state)).to.equal(false)
}) })
it('hasPrevious true', () => {
const state = { currentIndex: 1 }
expect(store.getters['hasPrevious'](state)).to.equal(true)
})
it('hasPrevious false', () => {
const state = { currentIndex: 0 }
expect(store.getters['hasPrevious'](state)).to.equal(false)
})
}) })
describe('actions', () => { describe('actions', () => {
it('append at end', (done) => { it('append at end', (done) => {