Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display lightbox after Video Play Finishes?

I have a youtube video.

I want to show a lightbox when it stops playing. I need this to be done using javascript/jQuery or PHP. Ajax is also fine.

I looked for a solution but didn't find one that worked.

like image 840
Jinal Dabhi Avatar asked Apr 21 '12 05:04

Jinal Dabhi


1 Answers

If you can use youtube api then, something like this should work:


<script type="text/javascript">
$(document).ready(function() {
var player;
    function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'YmHAAqOsBqA',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
    }
    function onPlayerReady(event) {
        event.target.playVideo();
    }
    function onPlayerStateChange(event) {        
        if(event.data === 0) {          
            //completed playing
            //open lightbox
            $('#yourElementId a').lightBox();
        }
    }
});
</script>

Did you mean something like this.

Hope it helps

like image 112
Sudhir Bastakoti Avatar answered Oct 03 '22 15:10

Sudhir Bastakoti