Issue #311 playback input improvements

This commit is contained in:
Akinwale Ariwodola 2017-07-01 21:33:23 +01:00
parent f6ad6e7ba7
commit b43ed0b64f

View file

@ -33,6 +33,7 @@ class VideoPlayer extends React.PureComponent {
renderMediaCallback.bind(this)
);
document.addEventListener("keydown", this.togglePlay.bind(this));
const mediaElement = this.refs.media.children[0];
if (mediaElement) {
mediaElement.addEventListener(
@ -42,6 +43,23 @@ class VideoPlayer extends React.PureComponent {
once: true,
}
);
mediaElement.addEventListener("click", this.togglePlay.bind(this));
}
}
togglePlay(event) {
// ignore all events except click and spacebar keydown
if ("keydown" === event.type && event.keyCode !== 32) {
return;
}
event.preventDefault();
const mediaElement = this.refs.media.children[0];
if (mediaElement) {
if (!mediaElement.paused) {
mediaElement.pause();
} else {
mediaElement.play();
}
}
}