-
Notifications
You must be signed in to change notification settings - Fork 2
/
media.js
27 lines (21 loc) · 899 Bytes
/
media.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
// Captures clicks on AirPods 3 or AirPods Pro using a video and the mediaSession
// API.
;(async () => {
const video = document.createElement("video")
document.body.prepend(video)
video.src =
"https://mdn.github.io/learning-area/html/multimedia-and-embedding/video-and-audio-content/rabbit320.mp4"
video.loop = true
video.controls = true
video.style.opacity = "0"
await video.play()
function handler(/** @type {MediaSessionActionDetails} */ { action }) {
console.log(action)
}
navigator.mediaSession.setActionHandler("pause", handler)
navigator.mediaSession.setActionHandler("play", handler)
navigator.mediaSession.setActionHandler("previoustrack", handler)
navigator.mediaSession.setActionHandler("nexttrack", handler)
navigator.mediaSession.setActionHandler("seekbackward", handler)
navigator.mediaSession.setActionHandler("seekforward", handler)
})()