refactor seek handlers
This commit is contained in:
parent
c751194c16
commit
d2eb884c51
@ -44,9 +44,6 @@ export const playerModule: Module<State, any> = {
|
|||||||
mediaSession.playbackState = 'paused'
|
mediaSession.playbackState = 'paused'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setPosition(state, time: number) {
|
|
||||||
audio.currentTime = time
|
|
||||||
},
|
|
||||||
setRepeat(state, enable) {
|
setRepeat(state, enable) {
|
||||||
state.repeat = enable
|
state.repeat = enable
|
||||||
localStorage.setItem('player.repeat', enable)
|
localStorage.setItem('player.repeat', enable)
|
||||||
@ -91,7 +88,7 @@ export const playerModule: Module<State, any> = {
|
|||||||
setNextInQueue(state, track) {
|
setNextInQueue(state, track) {
|
||||||
state.queue.splice(state.queueIndex + 1, 0, track)
|
state.queue.splice(state.queueIndex + 1, 0, track)
|
||||||
},
|
},
|
||||||
setProgress(state, value: any) {
|
setCurrentTime(state, value: any) {
|
||||||
state.currentTime = value
|
state.currentTime = value
|
||||||
},
|
},
|
||||||
setDuration(state, value: any) {
|
setDuration(state, value: any) {
|
||||||
@ -145,9 +142,9 @@ export const playerModule: Module<State, any> = {
|
|||||||
commit('setPlaying')
|
commit('setPlaying')
|
||||||
await audio.play()
|
await audio.play()
|
||||||
},
|
},
|
||||||
seek({ commit, state }, value) {
|
seek({ state }, value) {
|
||||||
if (isFinite(state.duration)) {
|
if (isFinite(state.duration)) {
|
||||||
commit('setPosition', state.duration * value)
|
audio.currentTime = state.duration * value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resetQueue({ commit }) {
|
resetQueue({ commit }) {
|
||||||
@ -196,7 +193,7 @@ export const playerModule: Module<State, any> = {
|
|||||||
|
|
||||||
export function setupAudio(store: Store<any>) {
|
export function setupAudio(store: Store<any>) {
|
||||||
audio.ontimeupdate = () => {
|
audio.ontimeupdate = () => {
|
||||||
store.commit('player/setProgress', audio.currentTime)
|
store.commit('player/setCurrentTime', audio.currentTime)
|
||||||
}
|
}
|
||||||
audio.ondurationchange = () => {
|
audio.ondurationchange = () => {
|
||||||
store.commit('player/setDuration', audio.duration)
|
store.commit('player/setDuration', audio.duration)
|
||||||
@ -230,15 +227,17 @@ export function setupAudio(store: Store<any>) {
|
|||||||
store.dispatch('player/pause')
|
store.dispatch('player/pause')
|
||||||
})
|
})
|
||||||
mediaSession.setActionHandler('seekto', (details) => {
|
mediaSession.setActionHandler('seekto', (details) => {
|
||||||
store.commit('player/setPosition', details.seekTime)
|
if (details.seekTime) {
|
||||||
|
audio.currentTime = details.seekTime
|
||||||
|
}
|
||||||
})
|
})
|
||||||
mediaSession.setActionHandler('seekforward', (details) => {
|
mediaSession.setActionHandler('seekforward', (details) => {
|
||||||
const offset = details.seekOffset || 10
|
const offset = details.seekOffset || 10
|
||||||
store.commit('player/setPosition', Math.min(audio.currentTime + offset, audio.duration))
|
audio.currentTime = Math.min(audio.currentTime + offset, audio.duration)
|
||||||
})
|
})
|
||||||
mediaSession.setActionHandler('seekbackward', (details) => {
|
mediaSession.setActionHandler('seekbackward', (details) => {
|
||||||
const offset = details.seekOffset || 10
|
const offset = details.seekOffset || 10
|
||||||
store.commit('player/setPosition', Math.max(audio.currentTime - offset, 0))
|
audio.currentTime = Math.max(audio.currentTime - offset, 0)
|
||||||
})
|
})
|
||||||
// FIXME
|
// FIXME
|
||||||
// function updatePositionState() {
|
// function updatePositionState() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user