wiredrive / wiredrive-player

Wiredrive Wordpress Video Player
http://www.wiredrive.com/rss
GNU Lesser General Public License v3.0
5 stars 4 forks source link

Trying to Stop the Player #36

Closed iamkevingreen closed 11 years ago

iamkevingreen commented 11 years ago

So I have two videos loading in modals and if I load one and close it I want it to stop the video.

The only way that I found to stop a flash video is with the code below. This works well for safari and the html5 player but the flash player throws an error and makes me click my close button twice. It works, but I could do without the error.

    $('.close').on("click", function() {
    alert('test')
        if (homeSlide == "intro") {
       var clone = $("#intro .videoM").clone(true);
       $("#intro .videoM").remove();
       $("#intro").html(clone);
       $('.videoM').delay(300).transition({
             opacity: '0',
             perspective: '0',
             scale: '0',
             top: '100%'
           }, 800)
     } else if (homeSlide == "reel") {
       var reel = $("#reel .videoM").clone(true);
       $("#reel .videoM").remove();
       $("#reel").html(reel);
       $('.videoM').delay(300).transition({
         opacity: '0',
         perspective: '0',
         scale: '0',
         top: '100%'
       }, 800)
     }
        homeSlide = "closed";
})

The error I am getting, basically cloning the container to stop the video:

Uncaught Error: WiredrivePlayer: attempting to initialize an already registered player id: content-id-51b898e2b7ecf

Any idea on a better way to stop the flash video?

rzurad commented 11 years ago

By cloning the entire container, you are not only changing the DOM element reference to the Flash object node or the HTML5 video node, but you're also cloning the initialization script that the plugin generates in place of the shortcode markup (the [wiredrive ...][/wiredrive] string). When you clone it, that init script is copied and reinserted into the DOM, which causes it to be reevaluated, triggering that error.

If you simply want to stop the video, then you can retrive the Player object from the WDP namespace and call its pause function. You only need to retrieve the id of the player you wish to stop. Currently the player ids are generated by WordPress and are subject to change on every page load, so you'll need to actually retrieve them from the DOM in order to assure that you are grabbing the correct player. The id field is on the container node that is given a CSS class of .wd-player, so if you only have one player on the page, this would be sufficient:

WDP.getPlayer($('.wd-player').attr('id')).pause();

That pause function will either pause the currently playing video, or stop the currently running slideshow.

Hope this helps. Let me know if this doesn't fix your issue.