mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
export default function enableMediaSession(webamp) {
|
|
if ("mediaSession" in navigator) {
|
|
/* global MediaMetadata */
|
|
webamp.__onTrackDidChange(({ title, artist, album, albumArtUrl }) => {
|
|
navigator.mediaSession.metadata = new MediaMetadata({
|
|
title,
|
|
artist,
|
|
album,
|
|
artwork: albumArtUrl
|
|
? [
|
|
{
|
|
src: albumArtUrl
|
|
// We don't currently know these.
|
|
// sizes: "96x96",
|
|
// type: "image/png"
|
|
}
|
|
]
|
|
: []
|
|
});
|
|
});
|
|
|
|
navigator.mediaSession.setActionHandler("play", () => {
|
|
webamp.play();
|
|
});
|
|
navigator.mediaSession.setActionHandler("pause", () => {
|
|
webamp.pause();
|
|
});
|
|
navigator.mediaSession.setActionHandler("seekbackward", () => {
|
|
webamp.seekBackward(10);
|
|
});
|
|
navigator.mediaSession.setActionHandler("seekforward", () => {
|
|
webamp.seekForward(10);
|
|
});
|
|
navigator.mediaSession.setActionHandler("previoustrack", () => {
|
|
webamp.previousTrack();
|
|
});
|
|
navigator.mediaSession.setActionHandler("nexttrack", () => {
|
|
webamp.nextTrack();
|
|
});
|
|
}
|
|
}
|