-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia-session.js
57 lines (48 loc) · 12.1 KB
/
media-session.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { getImageAsDataURI } from './utils.js';
export function initMediaSession(player) {
if (!('mediaSession' in navigator)) {
return;
}
function updateMediaSessionState() {
navigator.mediaSession.playbackState = player.audio.paused ? 'paused' : 'playing';
navigator.mediaSession.setPositionState({
duration: player.audio.duration,
position: player.audio.currentTime,
playbackRate: player.audio.playbackRate
});
}
async function updateMediaSessionMetadata() {
const artworkUrl = player.song.artworkUrl
? await getImageAsDataURI(player.song.artworkUrl)
: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAHr1JREFUeJztXQm0HkWVJiwCASUiSwYRHhAQXMYo6CBifIAgDhEyYDRx44kQcWFMIIa8NVfB5Ry2DJ4RcBCeqIggCKKC4yhPQAnIEhYDLkBQNlFIICwRCM5309Uvt+uv7r+7/+6q7v7rO+eefq+7uurW7Xv/2m7dWm89Dw8PDw8PDw8Pj3pi3rx5mw4MDGxLRFOGh4ffjOs00PSRkZHZuM7B9QRcR9SV/58NOoTTqfRTQNtwPq7r4uGRC1DgDYeGhl6L6wwod/+iRYu+hb9vAj0F+mdRhHyfBN2Iv0dBC1HWYbjuNnPmzA1cy8DDYy0WLFjwcvULfzKU9Yegu4s0gg6Mh/m4DNeTcP135tO1rDy6AFC2LUHvB50O5bstpwI/AVoOugN5/Bp0Fej7+P9czhf0RXXl/y9Wzzndneq9J3KWe6vK93Cuh2tZejQAUKTt0EJ8GMp5TtrWAekewfV61bXi8cSHcd2bxw5F8tbf3781xiVvR74fQRmLcL2ADQnXR1MazDKkP0uNfyYXyZtHgwFlmQS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OYRpxy16q7Ocgj331/JkgVp95jxPV2Oi09X/F6vJhGuVQi9v1xok0IMqz1lcD9ey9OgCZOnG2Cbw9Dh3/0DHMp+uZeXhwS3MZNDeMJoPgk6Ekp6F/38KWibPuCiInlZezJz/10ELuFwejJP3hfKoI6C4EwcGBrbFdQoHycN1Go8B+MxGXOfgegKuI+rK/89W+/GnqfRT+H2epnVdFw8PDw8PDw8PDw8PD49y8P8KHM8eA+VlPwAAAABJRU5ErkJggg==';
const artwork = {
src: artworkUrl,
type: artworkUrl.substring(artworkUrl.indexOf(':') + 1, artworkUrl.indexOf(';')),
};
navigator.mediaSession.metadata = new MediaMetadata({
title: player.song.title,
artist: player.song.artist,
album: player.song.album,
artwork: [artwork]
});
}
const actionHandlers = new Map([
['play', () => player.play()],
['pause', () => player.pause()],
['previoustrack', () => player.playPrevious()],
['nexttrack', () => player.playNext()],
['seekto', (e) => player.currentTime = e.seekTime]
]);
for (const [action, handler] of actionHandlers) {
try {
navigator.mediaSession.setActionHandler(action, handler);
} catch (e) {
console.log(`mediasession action ${action} not supported yet`)
}
}
const audioEvents = ['playing', 'paused', 'durationchange', 'ratechange', 'timechange'];
for (const event of audioEvents) {
player.audio.addEventListener(event, updateMediaSessionState);
}
player.addEventListener('playing', updateMediaSessionMetadata);
}