mediakeys lol

This commit is contained in:
Flummi 2021-12-23 07:18:33 +01:00
parent 17006f7e10
commit b2f45dc70e

View File

@ -1,6 +1,7 @@
(() => { (() => {
let video;
if(elem = document.querySelector("#my-video")) { if(elem = document.querySelector("#my-video")) {
const video = new v0ck(elem); video = new v0ck(elem);
document.addEventListener("keydown", e => { document.addEventListener("keydown", e => {
if(e.key === " " && e.target.tagName !== "INPUT") { if(e.key === " " && e.target.tagName !== "INPUT") {
video[video.paused ? 'play' : 'pause'](); video[video.paused ? 'play' : 'pause']();
@ -161,7 +162,7 @@
}, false); }, false);
// </swipe> // </swipe>
// <testzone> // <visualizer>
if(audioElement = document.querySelector("audio")) { if(audioElement = document.querySelector("audio")) {
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext("2d");
@ -204,5 +205,25 @@
audioCtx.resume(); audioCtx.resume();
}; };
} }
// </testzone> // </visualizer>
// <mediakeys>
if(elem = document.querySelector("#my-video") && "mediaSession" in navigator) {
const playpauseEvent = () => {
video[video.paused ? 'play' : 'pause']();
document.querySelector('.v0ck_overlay').classList[video.paused ? 'remove' : 'add']('v0ck_hidden');
};
navigator.mediaSession.setActionHandler('play', playpauseEvent);
navigator.mediaSession.setActionHandler('pause', playpauseEvent);
navigator.mediaSession.setActionHandler('stop', playpauseEvent);
navigator.mediaSession.setActionHandler('previoustrack', () => {
if(link = document.querySelector(".pagination > .prev:not(.disabled)"))
changePage(link);
});
navigator.mediaSession.setActionHandler('nexttrack', () => {
if(link = document.querySelector(".pagination > .next:not(.disabled)"))
changePage(link);
});
}
// </mediakeys>
})(); })();