Vianne Yu Zhèng Vianne Yu Zhèng - 21 days ago 5
jQuery Question

How to check if JPlayer is playing

How I can use Jquery to check if JPlayer is playing? I tried searching but it seems like all previous answers are already outdated as it doesn't work anymore with the latest version.

If(Jplayer is playing) {
$("#id").css("display", "block");
}
else {
$("#id").css("display", "none");
}

Answer

Try

$('.jp-play').click(function() {
  if($("#jquery_jplayer_1").data().jPlayer.status.paused === false){
                        $("p").show();
                    }
                    else{
                        $("p").hide();
                    }
});
$(document).ready(function(){
                $("#jquery_jplayer_1").jPlayer({
                    ready: function () {
                        $(this).jPlayer("setMedia", {
                            title: "Bubble",
                            m4a: "http://jplayer.org/audio/mp3/Miaow-07-Bubble.mp3",
                            oga: "http://jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"
                        }).jPlayer("play");
                    },
                    swfPath: "http://jplayer.org/latest/dist/jplayer",
                    supplied: "mp3, oga",
                    wmode: "window",
                    useStateClassSkin: true,
                    autoBlur: false,
                    smoothPlayBar: true,
                    keyEnabled: true,
                    remainingDuration: true,
                    toggleDuration: true
                });

                setTimeout(function(){
                    if($("#jquery_jplayer_1").data().jPlayer.status.paused === false){
                        $("p").hide();
                    }
                    else{
                        $("p").show();
                    }
                }, 500);
            }); 
Comments