Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VideoJS - unable to destroy and initialize

On VideoJS website you state that support was moved to StackOverflow, so let's try it here. I've got the following code:

var player = _V_('the_id', {}, function(){
    jQuery('.remove').on('click.destroyvideojs', function(){
        player.destroy();
        jQuery(this).unbind('click.destroyvideojs');
    });
});

It initializes video at first and it destroys it.

But when I want to initialize it again using the same exact piece of code, it doesn't work. It doesn't initialize the script on the same element ID (when it was removed from DOM and added again with correct initialization call after it's been added). I'm wondering why this might be happening?

Another try today:

var the_id = 'my_id';
var player = _V_(the_id, {}, function(){        
    player.destroy();
    _V_(the_id, {}, function(){
        alert('reinit');
    });
});

So, re-initialization of VideoJS simply doesn't work. Furthermore, it removed controls from the video now.

like image 740
Atadj Avatar asked Feb 11 '13 12:02

Atadj


2 Answers

In case this helps anyone, it looks like it's dispose in Version 4:

var player = videojs('my-video');
player.dispose();
like image 200
manafire Avatar answered Sep 27 '22 23:09

manafire


Having looked at the source for Video.js 5.0.0. @l:17236 You can just do the following:

if(videojs.getPlayers()[id]) {
    delete videojs.getPlayers()[id];
}
like image 35
Mwayi Avatar answered Sep 27 '22 22:09

Mwayi