Skip to content

Commit

Permalink
Fix: ad prerolls, specifically on iOS (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Aug 8, 2018
1 parent 904944e commit 4292fae
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ class VR extends Plugin {

this.setProjection(this.options_.projection);

// any time the video element is recycled for ads
// we have to reset the vr state and re-init after ad
this.on(player, 'adstart', () => player.setTimeout(() => {
// if the video element was recycled for this ad
if (!player.ads || !player.ads.videoElementRecycled()) {
this.log('video element not recycled for this ad, no need to reset');
return;
}

this.log('video element recycled for this ad, reseting');
this.reset();

this.one(player, 'playing', this.init);
}), 1);

this.on(player, 'loadedmetadata', this.init);
}

Expand Down Expand Up @@ -240,7 +255,7 @@ class VR extends Plugin {
}

msgs.forEach((msg) => {
videojs.log(msg);
videojs.log('VR: ', msg);
});
}

Expand Down Expand Up @@ -472,10 +487,10 @@ class VR extends Plugin {
this.getVideoEl_().style.display = 'none';

if (window.navigator.getVRDisplays) {
this.log('VR is supported, getting vr displays');
this.log('is supported, getting vr displays');
window.navigator.getVRDisplays().then((displays) => {
if (displays.length > 0) {
this.log('VR Displays found', displays);
this.log('Displays found', displays);
this.vrDisplay = displays[0];

// Native WebVR Head Mounted Displays (HMDs) like the HTC Vive
Expand Down Expand Up @@ -535,14 +550,17 @@ class VR extends Plugin {

if (this.controls3d) {
this.controls3d.dispose();
this.controls3d = null;
}

if (this.canvasPlayerControls) {
this.canvasPlayerControls.dispose();
this.canvasPlayerControls = null;
}

if (this.effect) {
this.effect.dispose();
this.effect = null;
}

window.removeEventListener('resize', this.handleResize_, true);
Expand Down Expand Up @@ -575,10 +593,6 @@ class VR extends Plugin {
// set the current projection to the default
this.currentProjection_ = this.defaultProjection_;

if (this.observer_) {
this.observer_.disconnect();
}

// reset the ios touch to click workaround
if (this.iosRevertTouchToClick_) {
this.iosRevertTouchToClick_();
Expand Down

0 comments on commit 4292fae

Please sign in to comment.