I have been working on a custom video controls for my school project and I wanted to add custom play/pause and sound/mute buttons, progress bar and volume slider. I followed tutorial on the play/pause and progress bar from yt video by iEatWebsites, works perfectly but once I started adding functions to other elements the play/pause button refuses to react and becomes unclickable. When I add function onclick alert with sound/mute button it still works and muting video with just command line also still works so i have no idea wheres the issue
everything is in controls div in html:
<header>
<div class="container">
<div class="c-video">
<video id="my_vid" class="video" src="video.mp4"></video>
<div class="controls">
<div class="buttons">
<button id="play-pause"></button>
</div>
<div class="green-bar">
<div class="green-juice"></div>
</div>
<div class="buttons2">
<button id="sound-mute"></button>
</div>
<div class="slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="volume">
</div>
</div>
</div>
</div>
</header>
and my .js file:
var video = document.querySelector(".video");
var juice = document.querySelector(".green-juice");
var btn = document.getElementById("play-pause");
var butn = document.getElementById("sound-mute");
var volume = document.querySelector("#volume")
function togglePlayPause() {
if (video.paused) {
btn.className = 'pause';
video.play();
} else {
btn.className = "play";
video.pause();
}
};
btn.onclick = function() {
togglePlayPause();
};
video.addEventListener('timeupdate', function(){
var juicePos = video.currentTime / video.duration;
juice.style.width = juicePos * 100 + "%";
if(video.ended){
btn.className = "play";
}
});
$("video").prop('muted', false); //mute
function videoMute() {
if $("video").prop('muted', false) {
$("video").prop('muted', true);
butn.className = "mute";
} else {
butn.className = "sound";
$("video").prop('muted', false);
}
};
butn.onclick = function() {
videoMute();
};
volume.addEventListener('timeupdate', function(e){
video.volume = e.currentTarget.nodeValue / 100;
});