Skip to content

Commit

Permalink
Do not use snapshots when playing stitched ads.
Browse files Browse the repository at this point in the history
  • Loading branch information
misteroneill committed Sep 8, 2017
1 parent 1d927fb commit 49a8d56
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ const contribAdsPlugin = function(options) {

// Returns a boolean indicating if given player is in live mode.
// Can be replaced when this is fixed: https://github.com/videojs/video.js/issues/3262
isLive(somePlayer) {
isLive(somePlayer = player) {
if (somePlayer.duration() === Infinity) {
return true;
} else if (videojs.browser.IOS_VERSION === '8' && somePlayer.duration() === 0) {
Expand All @@ -271,12 +271,18 @@ const contribAdsPlugin = function(options) {
// Return true if content playback should mute and continue during ad breaks.
// This is only done during live streams on platforms where it's supported.
// This improves speed and accuracy when returning from an ad break.
shouldPlayContentBehindAd(somePlayer) {
shouldPlayContentBehindAd(somePlayer = player) {
return !videojs.browser.IS_IOS &&
!videojs.browser.IS_ANDROID &&
somePlayer.duration() === Infinity;
},

// Return true if the player should take and restore snapshots during ad
// playback cycles.
shouldUseSnapshots() {
return !this.shouldPlayContentBehindAd() && !this.stitchedAds();
},

// Returns true if player is in ad mode.
//
// Ad mode definition:
Expand Down Expand Up @@ -470,7 +476,7 @@ const contribAdsPlugin = function(options) {
'ad-playback': {
enter() {
// capture current player state snapshot (playing, currentTime, src)
if (!player.ads.shouldPlayContentBehindAd(player)) {
if (player.ads.shouldUseSnapshots()) {
this.snapshot = snapshot.getPlayerSnapshot(player);
}

Expand Down Expand Up @@ -513,7 +519,7 @@ const contribAdsPlugin = function(options) {
if (player.ads.isLive(player)) {
player.addClass('vjs-live');
}
if (!player.ads.shouldPlayContentBehindAd(player)) {
if (player.ads.shouldUseSnapshots()) {
snapshot.restorePlayerSnapshot(player, this.snapshot);
}

Expand Down Expand Up @@ -569,7 +575,12 @@ const contribAdsPlugin = function(options) {
'postroll?': {
enter() {
player.ads._contentEnding = true;
this.snapshot = snapshot.getPlayerSnapshot(player);

// capture current player state snapshot (playing, currentTime, src)
if (player.ads.shouldUseSnapshots()) {
this.snapshot = snapshot.getPlayerSnapshot(player);
}

if (player.ads.nopostroll_) {
player.setTimeout(function() {
// content-resuming happens after the timeout for backward-compatibility
Expand Down

0 comments on commit 49a8d56

Please sign in to comment.