blob: 4d55db2189f047489f85142a93eb762aead6acb4 (
plain)
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
|
<!DOCTYPE HTML>
<html>
<head>
<title>Test frame for triggering media session's action handler</title>
<script src="MediaSessionTestUtils.js"></script>
</head>
<body>
<video id="testVideo" src="gizmo.mp4" loop></video>
<script>
const video = document.getElementById("testVideo");
const w = window.opener || window.parent;
window.onmessage = async event => {
if (event.data == "play") {
await video.play();
// As we can't observe `media-displayed-playback-changed` notification,
// that can only be observed in the chrome process. Therefore, we use a
// workaround instead which is to wait for a while to ensure that the
// controller has already been created in the chrome process.
let timeupdatecount = 0;
await new Promise(r => video.ontimeupdate = () => {
if (++timeupdatecount == 3) {
video.ontimeupdate = null;
r();
}
});
w.postMessage("played", "*");
}
}
// Setup the action handlers which would post the result back to the main window.
for (const action of gMediaSessionActions) {
navigator.mediaSession.setActionHandler(action, () => {
w.postMessage(action, "*");
});
}
</script>
</body>
</html>
|