Fix: Random crashes related to the mediaSession integration

This commit is contained in:
asivery 2021-09-18 01:10:35 +02:00
parent 852a7129d1
commit 8f8779a327
1 changed files with 4 additions and 4 deletions

View File

@ -141,20 +141,20 @@ export const Controls = () => {
navigator.mediaSession.metadata = null;
if (!initialized) {
setInitialized(true);
fakeAudio.play();
fakeAudio?.play();
if (deviceStatus?.state !== "playing") {
setTimeout(() => fakeAudio.pause(), 5000);
setTimeout(() => fakeAudio?.pause(), 5000);
}
}
navigator.mediaSession.setActionHandler("previoustrack", handlePrev);
navigator.mediaSession.setActionHandler("nexttrack", handleNext);
navigator.mediaSession.setActionHandler("pause", () => {
handlePause();
fakeAudio.pause();
fakeAudio?.pause();
});
navigator.mediaSession.setActionHandler("play", () => {
handlePlay();
fakeAudio.play();
fakeAudio?.play();
});
}
}, []);