mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
try & catch
This commit is contained in:
parent
f4914324bb
commit
c0cb334d24
@ -18,52 +18,60 @@ export default class MediaSession {
|
||||
}
|
||||
|
||||
update(manifest) {
|
||||
if ("mediaSession" in navigator) {
|
||||
return navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: manifest.title,
|
||||
try {
|
||||
if ("mediaSession" in navigator) {
|
||||
return navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: manifest.title,
|
||||
artist: manifest.artist,
|
||||
album: manifest.album,
|
||||
artwork: [
|
||||
{
|
||||
src: manifest.cover ?? manifest.thumbnail,
|
||||
sizes: "512x512",
|
||||
type: "image/jpeg",
|
||||
}
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
return CapacitorMusicControls.create({
|
||||
track: manifest.title,
|
||||
artist: manifest.artist,
|
||||
album: manifest.album,
|
||||
artwork: [
|
||||
{
|
||||
src: manifest.cover ?? manifest.thumbnail,
|
||||
sizes: "512x512",
|
||||
type: "image/jpeg",
|
||||
}
|
||||
],
|
||||
cover: manifest.cover,
|
||||
|
||||
hasPrev: false,
|
||||
hasNext: false,
|
||||
hasClose: true,
|
||||
|
||||
isPlaying: true,
|
||||
dismissable: false,
|
||||
|
||||
playIcon: "media_play",
|
||||
pauseIcon: "media_pause",
|
||||
prevIcon: "media_prev",
|
||||
nextIcon: "media_next",
|
||||
closeIcon: "media_close",
|
||||
notificationIcon: "notification"
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
return CapacitorMusicControls.create({
|
||||
track: manifest.title,
|
||||
artist: manifest.artist,
|
||||
album: manifest.album,
|
||||
cover: manifest.cover,
|
||||
|
||||
hasPrev: false,
|
||||
hasNext: false,
|
||||
hasClose: true,
|
||||
|
||||
isPlaying: true,
|
||||
dismissable: false,
|
||||
|
||||
playIcon: "media_play",
|
||||
pauseIcon: "media_pause",
|
||||
prevIcon: "media_prev",
|
||||
nextIcon: "media_next",
|
||||
closeIcon: "media_close",
|
||||
notificationIcon: "notification"
|
||||
})
|
||||
}
|
||||
|
||||
updateIsPlaying(to, timeElapsed = 0) {
|
||||
if ("mediaSession" in navigator) {
|
||||
return navigator.mediaSession.playbackState = to ? "playing" : "paused"
|
||||
}
|
||||
try {
|
||||
if ("mediaSession" in navigator) {
|
||||
return navigator.mediaSession.playbackState = to ? "playing" : "paused"
|
||||
}
|
||||
|
||||
return CapacitorMusicControls.updateIsPlaying({
|
||||
isPlaying: to,
|
||||
elapsed: timeElapsed,
|
||||
})
|
||||
return CapacitorMusicControls.updateIsPlaying({
|
||||
isPlaying: to,
|
||||
elapsed: timeElapsed,
|
||||
})
|
||||
} catch {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
@ -77,43 +85,47 @@ export default class MediaSession {
|
||||
}
|
||||
|
||||
handleControlsEvent(action) {
|
||||
const message = action.message
|
||||
try {
|
||||
const message = action.message
|
||||
|
||||
switch (message) {
|
||||
case "music-controls-next": {
|
||||
return app.cores.player.playback.next()
|
||||
}
|
||||
case "music-controls-previous": {
|
||||
return app.cores.player.playback.previous()
|
||||
}
|
||||
case "music-controls-pause": {
|
||||
return app.cores.player.playback.pause()
|
||||
}
|
||||
case "music-controls-play": {
|
||||
return app.cores.player.playback.play()
|
||||
}
|
||||
case "music-controls-destroy": {
|
||||
return app.cores.player.playback.stop()
|
||||
}
|
||||
switch (message) {
|
||||
case "music-controls-next": {
|
||||
return app.cores.player.playback.next()
|
||||
}
|
||||
case "music-controls-previous": {
|
||||
return app.cores.player.playback.previous()
|
||||
}
|
||||
case "music-controls-pause": {
|
||||
return app.cores.player.playback.pause()
|
||||
}
|
||||
case "music-controls-play": {
|
||||
return app.cores.player.playback.play()
|
||||
}
|
||||
case "music-controls-destroy": {
|
||||
return app.cores.player.playback.stop()
|
||||
}
|
||||
|
||||
// External controls (iOS only)
|
||||
case "music-controls-toggle-play-pause": {
|
||||
return app.cores.player.playback.toggle()
|
||||
}
|
||||
// External controls (iOS only)
|
||||
case "music-controls-toggle-play-pause": {
|
||||
return app.cores.player.playback.toggle()
|
||||
}
|
||||
|
||||
// Headset events (Android only)
|
||||
// All media button events are listed below
|
||||
case "music-controls-media-button": {
|
||||
return app.cores.player.playback.toggle()
|
||||
// Headset events (Android only)
|
||||
// All media button events are listed below
|
||||
case "music-controls-media-button": {
|
||||
return app.cores.player.playback.toggle()
|
||||
}
|
||||
case "music-controls-headset-unplugged": {
|
||||
return app.cores.player.playback.pause()
|
||||
}
|
||||
case "music-controls-headset-plugged": {
|
||||
return app.cores.player.playback.play()
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case "music-controls-headset-unplugged": {
|
||||
return app.cores.player.playback.pause()
|
||||
}
|
||||
case "music-controls-headset-plugged": {
|
||||
return app.cores.player.playback.play()
|
||||
}
|
||||
default:
|
||||
break;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user