Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VideoJS: Stopping video on modal close and not embedding in page

I have been using the JavaScript script VideoJS: http://videojs.com/ to build some video players that can be shown to the user in a popup. I have built the popup as follows:

        <script type="text/javascript"> 

            VideoJS.setupAllWhenReady();

            jQuery(document).ready(function ()
            {
                // videos have video js applied to them
                //$("video").VideoJS()

                $(".show-video").click(function ()
                {
                    $(".video-background").show();
                    $(".video-container").fadeIn("fast");
                });
                $(".close-video").click(function ()
                {
                    $('.video-background').fadeOut();
                    $('.video-container').fadeOut();

                });
            });
        </script>

<a class="show-video">Show Video</a>

        <div class="video-background">
            <div class="video-container">

                <div class="video-js-box vim-css">
                    <video id="video1" class="video-js" poster="wallpaper.png" controls="controls" width="1024" height="768">
                        <source src="video.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> 
                        <object id="flash_fallback_1" class="vjs-flash-fallback" width="1024" height="768" type="application/x-shockwave-flash"
                            data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"> 
                            <param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /> 
                            <param name="allowfullscreen" value="true" /> 
                            <param name="flashvars" value='config={"playlist":["poster.png", {"url": "video.mp4","autoPlay":false,"autoBuffering":true}]}' /> 
                          </object>
                    </video>
                </div>

                <a class="close-video">Close Video</a>

            </div>
        </div>

I have two problems:

1) If the video is playing and the user closes the video popup, the video will still be playing in the background... how do I stop this?

2) I've noticed on sites like: http://www.apple.com/imac/features.html that the videos popup in the same way by using a hashtag and id to show content but unlike in my example the video isn't in the page... any ideas on how they do this? As they arn't loading an external webpage. Would love to see some examples of how to do this with jQuery as I will be having multiple videos so would be great to just pull them in based on the hashtag on the link!

Thanks

like image 296
Cameron Avatar asked Aug 02 '11 08:08

Cameron


People also ask

How do I stop video when modal window is closed?

on('modalclosed', function() { console. log("Modal is closed then stop the video"); $('#video'). trigger('pause'); });

How do you stop a video from bootstrap modal is closed?

You can adjust this behaviour by adding in some Bootstrap javascript/jQuery that acts to stop the video if either the modal window is either clicked to close or the background is clicked to dismiss the modal.

Can Videojs play audio?

Playing audio through Videojs and Nuevo pluginNuevo plugin has an extra audioInfo option, that you can add along other plugin options. It allows to define song information, like album cover, artist, song title, genre and release date. Certainly it makes your player layout more attractive.


2 Answers

http://help.videojs.com/discussions/suggestions/9-play-and-pause-video-via-jquery

Put in function where you want your video to pause in "jquery.reveal.js"

$(".video-js")[0].player.pause();
like image 140
Paul Avatar answered Sep 18 '22 15:09

Paul


There are 2 ways you can do this.

  1. Remove the whole video when the popup is closed. Use $(video).remove()
  2. Use the videojs javascript method

    VideoJS.DOMReady(function(){
      var myPlayer = VideoJS.setup("example_video_1");
      myPlayer.pause();  
    });
    
like image 28
vinay Avatar answered Sep 18 '22 15:09

vinay