Kilvish Shakal Kilvish Shakal - 1 month ago 6
CSS Question

Check if a HTML5 video is playing using jquery

I've written a small jquery code to override HTML 5 play function. However, I am not able to check if a video is playing or not.
Here is my jquery code

$("video").click(function() {
var video = $("#myvideo").get(0);
video.play();
$(".play").css("display", "none");
return false;
});
$("#myvideo").bind("pause ended", function() {
$(".play").css("display", "block");
});


Just give me simple tips to show a div with
class="pause"
(I have CSS for it) when the video is paused and pause the video as well.

Answer

You'd use the paused property to check if the video is paused.
If it's not paused, it's playing

$("video").click(function() {
    var video = $("#myvideo").get(0);

    if ( video.paused ) {
        video.play();
        $(".play").hide();
        $(".pause").show();
    } else {
        video.pause();
        $(".play").show();
        $(".pause").hide();
    }

    return false;
});