<video id="myVideo" src=""></video>
<script>
var myVideo = document.getElementById("myVideo");
playVideo();
function playVideo(videoId) {
myVideo.controls = true;
myVideo.autoplay = true;
myVideo.muted = true;
console.log("Key:"+videoId);
if (videoId == "KeyB") {
console.log("KeyB");
myVideo.loop = false;
myVideo.src = "videoB.mp4";
}
else if (videoId == "KeyC") {
console.log("KeyC");
myVideo.loop = false;
myVideo.src = "videoC.mp4";
}
else if (videoId == "KeyD") {
console.log("KeyD");
myVideo.loop = false;
myVideo.src = "videoD.mp4";
}
else if (videoId == "KeyE") {
console.log("KeyE");
myVideo.loop = false;
myVideo.src = "videoE.mp4";
}
else {
myVideo.loop = true;
myVideo.src = "default.mp4";
}
myVideo.load();
return;
}
window.addEventListener("keydown", function(event) {
if (event.defaultPrevented) {
return;
}
playVideo(event.code);
event.preventDefault();
}, true);
</script>