videojs / videojs-contrib-ads

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

feat: Add `allowVjsAutoplay` option to add support for custom video.js autoplay settings #532

Closed alex-barstow closed 3 years ago

alex-barstow commented 3 years ago

Description

Video.js recently added new functionality for autoplay that triggers autoplay-success or autoplay-failure events depending on the result of the autoplay attempt. However, that functionality relies on the initial play promise being resolved/rejected naturally, so it is not compatible with the contrib-ads callPlay() middleware which terminates the first play request.

This PR adds an option to bypass that play termination if the player intends to autoplay. It does this by conditionally setting _shouldBlockPlay to false in the BeforePreroll state if the option is true and player.autoplay() is truthy.