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; navigator.mediaSession.metadata = null;
if (!initialized) { if (!initialized) {
setInitialized(true); setInitialized(true);
fakeAudio.play(); fakeAudio?.play();
if (deviceStatus?.state !== "playing") { if (deviceStatus?.state !== "playing") {
setTimeout(() => fakeAudio.pause(), 5000); setTimeout(() => fakeAudio?.pause(), 5000);
} }
} }
navigator.mediaSession.setActionHandler("previoustrack", handlePrev); navigator.mediaSession.setActionHandler("previoustrack", handlePrev);
navigator.mediaSession.setActionHandler("nexttrack", handleNext); navigator.mediaSession.setActionHandler("nexttrack", handleNext);
navigator.mediaSession.setActionHandler("pause", () => { navigator.mediaSession.setActionHandler("pause", () => {
handlePause(); handlePause();
fakeAudio.pause(); fakeAudio?.pause();
}); });
navigator.mediaSession.setActionHandler("play", () => { navigator.mediaSession.setActionHandler("play", () => {
handlePlay(); handlePlay();
fakeAudio.play(); fakeAudio?.play();
}); });
} }
}, []); }, []);