Created
July 2, 2019 21:04
-
-
Save mvalim/de15730c9c7ebc8a5b1fc583ca3ec8a3 to your computer and use it in GitHub Desktop.
Chrome mediaSession global shortcuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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