videojs / videojs-contrib-ads

A Tool for Building Video.js Ad Plugins
http://videojs.github.io/videojs-contrib-ads/
Other
381 stars 257 forks source link

Preroll not starting when following simple exemple #509

Open morgantmsn opened 4 years ago

morgantmsn commented 4 years ago

Description

When implementing a simple preroll the user have to click 2 times in order for the video preroll to start. I basically followed the steps on

http://videojs.github.io/videojs-contrib-ads/integrator/getting-started.html

Steps to Reproduce

Here is my code

options.src is https url to an mp4 video

I tried to manually call player.play() but the video didn't start then I wrapped the player.play() call in setTimeout with a 0 timeout hoping that this will push the call at the end of the stack and will work but it didn't. Finally I wrapped the call to player.play() with a 100ms timeout and this works, but I don't think that this will solve my issue in any cases. (Commented part on the code)

 player.ads();

player.on("contentchanged", function () {
        player.trigger("adsready");
});

player.one("readyforpreroll", function () {
        player.ads.startLinearAdMode(); // create snapshot of the source
        player.src(options.src);
        //  player.play(); don't work either
        // setTimeout(function () {
        //     player.play().then(function () {
        //         console.log("video started");
        //     });
        // }, 100);
        // Only fix found on on video not starting
    });

Expected Results

Expecting the preroll to play

Actual Results

I Have to click on the player again in order for the video to start

Versions

videojs-contrib-ads version: 6.6.5

Video-js version: 7.6.6

Platforms

Browsers: Firefox 73.0b10 - Version 79.0.3945.130

OS/Devices: eg. MacOS 10.15.2