file_trigger_actionhandler_frame.html (1194B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test frame for triggering media session's action handler</title> 5 <script src="MediaSessionTestUtils.js"></script> 6 </head> 7 <body> 8 <video id="testVideo" src="gizmo.mp4" loop></video> 9 <script> 10 11 const video = document.getElementById("testVideo"); 12 const w = window.opener || window.parent; 13 14 window.onmessage = async event => { 15 if (event.data == "play") { 16 await video.play(); 17 // As we can't observe `media-displayed-playback-changed` notification, 18 // that can only be observed in the chrome process. Therefore, we use a 19 // workaround instead which is to wait for a while to ensure that the 20 // controller has already been created in the chrome process. 21 let timeupdatecount = 0; 22 await new Promise(r => video.ontimeupdate = () => { 23 if (++timeupdatecount == 3) { 24 video.ontimeupdate = null; 25 r(); 26 } 27 }); 28 w.postMessage("played", "*"); 29 } 30 } 31 32 // Setup the action handlers which would post the result back to the main window. 33 for (const action of gMediaSessionActions) { 34 navigator.mediaSession.setActionHandler(action, () => { 35 w.postMessage(action, "*"); 36 }); 37 } 38 </script> 39 </body> 40 </html>