I'm trying to create control buttons using jQuery for my html5 video, which is hosted locally. However I can't seem to get the buttons to work. I have tried different methods of coding but seem to work.
$(function(){
var video = $('#video').get(0);
$(document).delegate('#play-button', 'click', function() {
video.load();
video.play();
$('#play-button').addClass('hide');
});
$(document).delegate('#pause', 'click', function() {
if (video.play() === true) {
video.pause();
} else {
$('#pause > img').attr('src', 'image/play.png');
video.play();
}
});
$(document).delegate('#stop', 'click', function() {
video.stop();
video.currentTime = 0;
});
});
<div id="video-controls">
<button type="button" role="button" id="play-button"><img src="<?php echo get_template_directory_uri () ?>/images/play.png" alt="play"></button>
<button type="button" role="button" id="pause"><img src="<?php echo get_template_directory_uri () ?>/images/pause.png" alt="pause"></button>
<button type="button" role="button" id="stop"><img src="<?php echo get_template_directory_uri () ?>/images/stop.png" alt="stop"></button>
</div>
What I'm trying to do is show a play button in the middle of the video and once clicked it will play the video but then hide. So to pause and stop the video the user will need to hover over the video and the controls will appear.
Any advice will be appreciated. Thanks for taking the time to look at my question.
#play-button