This commit is contained in:
parent
422eb92f17
commit
456661a324
|
@ -0,0 +1 @@
|
||||||
|
Fixed skipped track when appending multiple tracks to the queue under certain conditions (#209)
|
|
@ -59,7 +59,7 @@ export default {
|
||||||
isEmpty: state => state.tracks.length === 0
|
isEmpty: state => state.tracks.length === 0
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
append ({commit, state, dispatch}, {track, index, skipPlay}) {
|
append ({commit, state, dispatch}, {track, index}) {
|
||||||
index = index || state.tracks.length
|
index = index || state.tracks.length
|
||||||
if (index > state.tracks.length - 1) {
|
if (index > state.tracks.length - 1) {
|
||||||
// we simply push to the end
|
// we simply push to the end
|
||||||
|
@ -68,9 +68,6 @@ export default {
|
||||||
// we insert the track at given position
|
// we insert the track at given position
|
||||||
commit('insert', {track, index})
|
commit('insert', {track, index})
|
||||||
}
|
}
|
||||||
if (!skipPlay) {
|
|
||||||
dispatch('resume')
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
appendMany ({state, dispatch}, {tracks, index, callback}) {
|
appendMany ({state, dispatch}, {tracks, index, callback}) {
|
||||||
|
@ -82,13 +79,12 @@ export default {
|
||||||
}
|
}
|
||||||
let total = tracks.length
|
let total = tracks.length
|
||||||
tracks.forEach((t, i) => {
|
tracks.forEach((t, i) => {
|
||||||
let p = dispatch('append', {track: t, index: index, skipPlay: true})
|
let p = dispatch('append', {track: t, index: index})
|
||||||
index += 1
|
index += 1
|
||||||
if (callback && i + 1 === total) {
|
if (callback && i + 1 === total) {
|
||||||
p.then(callback)
|
p.then(callback)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
dispatch('resume')
|
|
||||||
},
|
},
|
||||||
|
|
||||||
cleanTrack ({state, dispatch, commit}, index) {
|
cleanTrack ({state, dispatch, commit}, index) {
|
||||||
|
@ -110,11 +106,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
resume ({state, dispatch, rootState}) {
|
|
||||||
if (state.ended | rootState.player.errored) {
|
|
||||||
dispatch('next')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
previous ({state, dispatch, rootState}) {
|
previous ({state, dispatch, rootState}) {
|
||||||
if (state.currentIndex > 0 && rootState.player.currentTime < 3) {
|
if (state.currentIndex > 0 && rootState.player.currentTime < 3) {
|
||||||
dispatch('currentIndex', state.currentIndex - 1)
|
dispatch('currentIndex', state.currentIndex - 1)
|
||||||
|
|
|
@ -88,7 +88,7 @@ describe('store/queue', () => {
|
||||||
it('append at end', () => {
|
it('append at end', () => {
|
||||||
testAction({
|
testAction({
|
||||||
action: store.actions.append,
|
action: store.actions.append,
|
||||||
payload: {track: 4, skipPlay: true},
|
payload: {track: 4},
|
||||||
params: {state: {tracks: [1, 2, 3]}},
|
params: {state: {tracks: [1, 2, 3]}},
|
||||||
expectedMutations: [
|
expectedMutations: [
|
||||||
{ type: 'insert', payload: {track: 4, index: 3} }
|
{ type: 'insert', payload: {track: 4, index: 3} }
|
||||||
|
@ -98,26 +98,13 @@ describe('store/queue', () => {
|
||||||
it('append at index', () => {
|
it('append at index', () => {
|
||||||
testAction({
|
testAction({
|
||||||
action: store.actions.append,
|
action: store.actions.append,
|
||||||
payload: {track: 2, index: 1, skipPlay: true},
|
payload: {track: 2, index: 1},
|
||||||
params: {state: {tracks: [1, 3]}},
|
params: {state: {tracks: [1, 3]}},
|
||||||
expectedMutations: [
|
expectedMutations: [
|
||||||
{ type: 'insert', payload: {track: 2, index: 1} }
|
{ type: 'insert', payload: {track: 2, index: 1} }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('append and play', () => {
|
|
||||||
testAction({
|
|
||||||
action: store.actions.append,
|
|
||||||
payload: {track: 3},
|
|
||||||
params: {state: {tracks: [1, 2]}},
|
|
||||||
expectedMutations: [
|
|
||||||
{ type: 'insert', payload: {track: 3, index: 2} }
|
|
||||||
],
|
|
||||||
expectedActions: [
|
|
||||||
{ type: 'resume' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('appendMany', () => {
|
it('appendMany', () => {
|
||||||
const tracks = [{title: 1}, {title: 2}]
|
const tracks = [{title: 1}, {title: 2}]
|
||||||
testAction({
|
testAction({
|
||||||
|
@ -125,9 +112,8 @@ describe('store/queue', () => {
|
||||||
payload: {tracks: tracks},
|
payload: {tracks: tracks},
|
||||||
params: {state: {tracks: []}},
|
params: {state: {tracks: []}},
|
||||||
expectedActions: [
|
expectedActions: [
|
||||||
{ type: 'append', payload: {track: tracks[0], index: 0, skipPlay: true} },
|
{ type: 'append', payload: {track: tracks[0], index: 0} },
|
||||||
{ type: 'append', payload: {track: tracks[1], index: 1, skipPlay: true} },
|
{ type: 'append', payload: {track: tracks[1], index: 1} },
|
||||||
{ type: 'resume' }
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -138,9 +124,8 @@ describe('store/queue', () => {
|
||||||
payload: {tracks: tracks, index: 1},
|
payload: {tracks: tracks, index: 1},
|
||||||
params: {state: {tracks: [1, 2]}},
|
params: {state: {tracks: [1, 2]}},
|
||||||
expectedActions: [
|
expectedActions: [
|
||||||
{ type: 'append', payload: {track: tracks[0], index: 1, skipPlay: true} },
|
{ type: 'append', payload: {track: tracks[0], index: 1} },
|
||||||
{ type: 'append', payload: {track: tracks[1], index: 2, skipPlay: true} },
|
{ type: 'append', payload: {track: tracks[1], index: 2} },
|
||||||
{ type: 'resume' }
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -179,31 +164,6 @@ describe('store/queue', () => {
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('resume when ended', () => {
|
|
||||||
testAction({
|
|
||||||
action: store.actions.resume,
|
|
||||||
params: {state: {ended: true}, rootState: {player: {errored: false}}},
|
|
||||||
expectedActions: [
|
|
||||||
{ type: 'next' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('resume when errored', () => {
|
|
||||||
testAction({
|
|
||||||
action: store.actions.resume,
|
|
||||||
params: {state: {ended: false}, rootState: {player: {errored: true}}},
|
|
||||||
expectedActions: [
|
|
||||||
{ type: 'next' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('skip resume when not ended or not error', () => {
|
|
||||||
testAction({
|
|
||||||
action: store.actions.resume,
|
|
||||||
params: {state: {ended: false}, rootState: {player: {errored: false}}},
|
|
||||||
expectedActions: []
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('previous when at beginning', () => {
|
it('previous when at beginning', () => {
|
||||||
testAction({
|
testAction({
|
||||||
action: store.actions.previous,
|
action: store.actions.previous,
|
||||||
|
|
Loading…
Reference in New Issue