Added basic keyboard controls for seeking and play/pause
This commit is contained in:
parent
ab0f6613e7
commit
667144adcb
@ -384,6 +384,8 @@
|
||||
}
|
||||
});
|
||||
|
||||
this.initKeyboard();
|
||||
|
||||
// attach the shadow root
|
||||
this.shadowRoot.append(this._root);
|
||||
}
|
||||
@ -824,6 +826,39 @@
|
||||
window.requestAnimationFrame(paintBuffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up keyboard bindings.
|
||||
*/
|
||||
initKeyboard() {
|
||||
this._root.addEventListener('keydown', (event) => {
|
||||
switch(event.key) {
|
||||
case " ":
|
||||
this.togglePlayback();
|
||||
break;
|
||||
case "ArrowRight":
|
||||
if(event.target === this._volumeSlider) {
|
||||
break;
|
||||
}
|
||||
let ahead = this._controlSource.currentTime + 5;
|
||||
if(ahead > this._controlSource.duration) {
|
||||
ahead = this._controlSource.duration;
|
||||
}
|
||||
this.setTime(ahead);
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
if(event.target === this._volumeSlider) {
|
||||
break;
|
||||
}
|
||||
let back = this._controlSource.currentTime - 5;
|
||||
if(back < 0) {
|
||||
back = 0;
|
||||
}
|
||||
this.setTime(back);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Apply any saved settings from previous usage
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user