At this moment I'm quite frustrated. I want to control a video via javascript:
- set the volume to 20%
- play & pause by clicking the video
That for I have this html (which also includes a little php)
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="player.js" type="text/javascript"></script>
</head>
<body>
<?php
if(isset($_GET["id"])) {
$video = $_GET["id"];
}else{
$video = "test.mp4";
}
?>
<video id="video" preload="auto" autoplay="true" loop="loop">
<?php echo "<source src=\"$video\" type=\"video/mp4\">"; ?>
<source src="movie.webm" type="video/webm">
Sorry, your browser does not support HTML5 video.
</video>
</body>
player.js:
var vid = document.getElementById('video');
vid.volume = 0.2;
vid.addEventListener('click', function () {
if (vid.paused == false) {
vid.pause();
vid.firstChild.nodeValue = 'Play';
} else {
vid.play();
vid.firstChild.nodeValue = 'Pause';
}
});
But Chromes console's just showing: Uncaught TypeError: Cannot set property 'volume' of null
Why is that?
Thanks in advance!