try & catch

This commit is contained in:
SrGooglo 2023-08-27 21:31:31 +00:00
parent e59edfa86f
commit 7c26aba3a6

View File

@ -18,6 +18,7 @@ export default class MediaSession {
} }
update(manifest) { update(manifest) {
try {
if ("mediaSession" in navigator) { if ("mediaSession" in navigator) {
return navigator.mediaSession.metadata = new MediaMetadata({ return navigator.mediaSession.metadata = new MediaMetadata({
title: manifest.title, title: manifest.title,
@ -53,9 +54,13 @@ export default class MediaSession {
closeIcon: "media_close", closeIcon: "media_close",
notificationIcon: "notification" notificationIcon: "notification"
}) })
} catch (error) {
console.error(error)
}
} }
updateIsPlaying(to, timeElapsed = 0) { updateIsPlaying(to, timeElapsed = 0) {
try {
if ("mediaSession" in navigator) { if ("mediaSession" in navigator) {
return navigator.mediaSession.playbackState = to ? "playing" : "paused" return navigator.mediaSession.playbackState = to ? "playing" : "paused"
} }
@ -64,6 +69,9 @@ export default class MediaSession {
isPlaying: to, isPlaying: to,
elapsed: timeElapsed, elapsed: timeElapsed,
}) })
} catch {
console.error(error)
}
} }
destroy() { destroy() {
@ -77,6 +85,7 @@ export default class MediaSession {
} }
handleControlsEvent(action) { handleControlsEvent(action) {
try {
const message = action.message const message = action.message
switch (message) { switch (message) {
@ -115,5 +124,8 @@ export default class MediaSession {
default: default:
break; break;
} }
} catch (error) {
console.error(error)
}
} }
} }