mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
try & catch
This commit is contained in:
parent
e59edfa86f
commit
7c26aba3a6
@ -18,52 +18,60 @@ export default class MediaSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(manifest) {
|
update(manifest) {
|
||||||
if ("mediaSession" in navigator) {
|
try {
|
||||||
return navigator.mediaSession.metadata = new MediaMetadata({
|
if ("mediaSession" in navigator) {
|
||||||
title: manifest.title,
|
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,
|
artist: manifest.artist,
|
||||||
album: manifest.album,
|
album: manifest.album,
|
||||||
artwork: [
|
cover: manifest.cover,
|
||||||
{
|
|
||||||
src: manifest.cover ?? manifest.thumbnail,
|
hasPrev: false,
|
||||||
sizes: "512x512",
|
hasNext: false,
|
||||||
type: "image/jpeg",
|
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) {
|
updateIsPlaying(to, timeElapsed = 0) {
|
||||||
if ("mediaSession" in navigator) {
|
try {
|
||||||
return navigator.mediaSession.playbackState = to ? "playing" : "paused"
|
if ("mediaSession" in navigator) {
|
||||||
}
|
return navigator.mediaSession.playbackState = to ? "playing" : "paused"
|
||||||
|
}
|
||||||
|
|
||||||
return CapacitorMusicControls.updateIsPlaying({
|
return CapacitorMusicControls.updateIsPlaying({
|
||||||
isPlaying: to,
|
isPlaying: to,
|
||||||
elapsed: timeElapsed,
|
elapsed: timeElapsed,
|
||||||
})
|
})
|
||||||
|
} catch {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
@ -77,43 +85,47 @@ export default class MediaSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleControlsEvent(action) {
|
handleControlsEvent(action) {
|
||||||
const message = action.message
|
try {
|
||||||
|
const message = action.message
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case "music-controls-next": {
|
case "music-controls-next": {
|
||||||
return app.cores.player.playback.next()
|
return app.cores.player.playback.next()
|
||||||
}
|
}
|
||||||
case "music-controls-previous": {
|
case "music-controls-previous": {
|
||||||
return app.cores.player.playback.previous()
|
return app.cores.player.playback.previous()
|
||||||
}
|
}
|
||||||
case "music-controls-pause": {
|
case "music-controls-pause": {
|
||||||
return app.cores.player.playback.pause()
|
return app.cores.player.playback.pause()
|
||||||
}
|
}
|
||||||
case "music-controls-play": {
|
case "music-controls-play": {
|
||||||
return app.cores.player.playback.play()
|
return app.cores.player.playback.play()
|
||||||
}
|
}
|
||||||
case "music-controls-destroy": {
|
case "music-controls-destroy": {
|
||||||
return app.cores.player.playback.stop()
|
return app.cores.player.playback.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// External controls (iOS only)
|
// External controls (iOS only)
|
||||||
case "music-controls-toggle-play-pause": {
|
case "music-controls-toggle-play-pause": {
|
||||||
return app.cores.player.playback.toggle()
|
return app.cores.player.playback.toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Headset events (Android only)
|
// Headset events (Android only)
|
||||||
// All media button events are listed below
|
// All media button events are listed below
|
||||||
case "music-controls-media-button": {
|
case "music-controls-media-button": {
|
||||||
return app.cores.player.playback.toggle()
|
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": {
|
} catch (error) {
|
||||||
return app.cores.player.playback.pause()
|
console.error(error)
|
||||||
}
|
|
||||||
case "music-controls-headset-plugged": {
|
|
||||||
return app.cores.player.playback.play()
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user