-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (28 loc) · 930 Bytes
/
script.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
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: 'Bad Apple!!',
album: 'Lovelight',
artist: 'nomico'
})
}
/** @type {HTMLVideoElement} */
const video = document.getElementById("video")
/** @type {HTMLCanvasElement} */
const canvas = document.getElementById("canvas")
const ctx = canvas.getContext('2d')
// Takes up the UI thread less, but it's more choppy
// video.addEventListener("timeupdate", () => {
// ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
// navigator.mediaSession.metadata.artwork = [
// { src: canvas.toDataURL(), type: "image/png" }
// ]
// })
function update() {
if (video.paused || video.ended) return
ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
navigator.mediaSession.metadata.artwork = [
{ src: canvas.toDataURL(), type: "image/png" }
]
setTimeout(() => update(), 0)
}
video.addEventListener("play", () => update())