Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"VIDEOJS: WARN: Player "media" is already initialized" when it is not

I currently experience a small issue where I receive a warning from video.js which is as following:

VIDEOJS: WARN: Player "media" is already initialized. Options will not be applied.

The bizarre thing is that it has not been initialized. But rather it is within a jQuery's $(document).ready.

The relevant code is:

<script src="//vjs.zencdn.net/5.19.1/video.min.js"></script>

<script>
    $(document).ready(function() {
        var player = videojs('media', {
            fluid: true,
            playbackRates: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]
        });
    });
<script>

It know it has something to do with when how fast these resources get loaded, because every now and then the warning will not appear and the options are applied.

I do need this the player initialized once the "document is ready", though. How can I go about this issue?

Any help I would greatly appreciate!

like image 871
Chris Avatar asked Oct 21 '25 12:10

Chris


2 Answers

I had the same problem. Videojs gets automatically initialized when the data-setup attribute is present in the <video> tag.

Remove data-setup and the player will not initialize by itself, the warning will not show up anymore when you execute the JS code now:

var player = videojs('media', options);

Now you can define the options and simply do ("media" is the id of your videoplayer):

var options = {
    "playbackRates": [1, 1.5, 2],
};

var video = videojs('media', options);

video.ready(function() {
    // …
});
like image 179
Avatar Avatar answered Oct 23 '25 07:10

Avatar


I also face the same problem. Videojs gets automatically initialized

Just Remove "data-setup" and the player will not initialize by itself

remove data-setup

like image 43
talha baig Avatar answered Oct 23 '25 08:10

talha baig