check if we paused on duck before playing again (#51)

prevents music playing after an alarm or call ends if it wasn't paused by that alarm/call in the first place
This commit is contained in:
austinried 2021-12-15 13:59:58 +09:00 committed by GitHub
parent 5bb32df16b
commit da033e697f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -34,6 +34,12 @@ const rebuildQueue = () => {
})
}
const setDuckPaused = (duckPaused: boolean) => {
unstable_batchedUpdates(() => {
useStore.getState().setDuckPaused(duckPaused)
})
}
let serviceCreated = false
const createService = async () => {
@ -81,9 +87,14 @@ const createService = async () => {
}
if (data.paused) {
let state = useStore.getState().playerState
if (state === State.Playing || state === State.Buffering || state === State.Connecting) {
trackPlayerCommands.enqueue(TrackPlayer.pause)
} else {
setDuckPaused(true)
}
} else if (useStore.getState().duckPaused) {
trackPlayerCommands.enqueue(TrackPlayer.play)
setDuckPaused(false)
}
})

View File

@ -42,6 +42,9 @@ export type TrackPlayerSlice = {
playerState: State
setPlayerState: (playerState: State) => void
duckPaused: boolean
setDuckPaused: (duckPaused: boolean) => void
currentTrack?: TrackExt
currentTrackIdx?: number
setCurrentTrackIdx: (idx?: number) => void
@ -197,6 +200,9 @@ export const createTrackPlayerSlice = (set: SetState<Store>, get: GetState<Store
)
},
duckPaused: false,
setDuckPaused: duckPaused => set({ duckPaused }),
queue: [],
setQueue: async (songs, name, contextType, contextId, playTrack, shuffle) => {
return trackPlayerCommands.enqueue(async () => {