Skip to content

Instantly share code, notes, and snippets.

@mvalim
Created July 2, 2019 21:04
Show Gist options
  • Save mvalim/de15730c9c7ebc8a5b1fc583ca3ec8a3 to your computer and use it in GitHub Desktop.
Save mvalim/de15730c9c7ebc8a5b1fc583ca3ec8a3 to your computer and use it in GitHub Desktop.
Chrome mediaSession global shortcuts
function video() {
return Array.from(document.querySelectorAll('video'))
.filter((v) => v.readyState !== 0)
.sort((v1, v2) => {
const v1Rect = v1.getClientRects()[0];
const v2Rect = v2.getClientRects()[0];
return ((v2Rect.width * v2Rect.height) - (v1Rect.width * v1Rect.height));
})[0];
}
navigator.mediaSession.setActionHandler('previoustrack', () => {
console.log('previoustrack');
video().currentTime = video().currentTime - 10;
});
navigator.mediaSession.setActionHandler('nexttrack', () => {
console.log('nexttrack');
video().currentTime = video().currentTime + 10;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment