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
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) {
trackPlayerCommands.enqueue(TrackPlayer.pause)
} else {
let state = useStore.getState().playerState
if (state === State.Playing || state === State.Buffering || state === State.Connecting) {
trackPlayerCommands.enqueue(TrackPlayer.pause)
setDuckPaused(true)
}
} else if (useStore.getState().duckPaused) {
trackPlayerCommands.enqueue(TrackPlayer.play)
setDuckPaused(false)
}
})