Skip to content

Commit

Permalink
fix: content restarts from the beginning when snapshot restores sourc…
Browse files Browse the repository at this point in the history
…e after midroll in iOS

* add autoplay to force preloading after src change in iOS, fix wip

* minor changes

* edit comments
  • Loading branch information
alex-barstow authored Nov 16, 2017
1 parent 448defe commit 64f1587
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ export function restorePlayerSnapshot(player, snapshotObject) {
if (!snapshotObject.ended) {
player.play();
}

// if we added autoplay to force content loading on iOS, remove it now
// that it has served its purpose
if (player.ads.shouldRemoveAutoplay_) {
player.autoplay(false);
player.ads.shouldRemoveAutoplay_ = false;
}
};

// determine if the video element has loaded enough of the snapshot source
Expand Down Expand Up @@ -197,6 +204,16 @@ export function restorePlayerSnapshot(player, snapshotObject) {
// on ios7, fiddling with textTracks too early will cause safari to crash
player.one('contentloadedmetadata', restoreTracks);

// adding autoplay guarantees that Safari will load the content so we can
// seek back to the correct time after ads
if (videojs.browser.IS_IOS && !player.autoplay()) {
player.autoplay(true);

// if we get here, the player was not originally configured to autoplay,
// so we should remove it after it has served its purpose
player.ads.shouldRemoveAutoplay_ = true;
}

// if the src changed for ad playback, reset it
player.src({ src: snapshotObject.currentSrc, type: snapshotObject.type });

Expand Down

0 comments on commit 64f1587

Please sign in to comment.