diff --git a/package.json b/package.json index c99eb749..65f7a913 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,6 @@ "lodash": "~3.10.1", "qunitjs": "^1.17.1", "sinon": "~1.16.1", - "video.js": "5.0.0-rc.102" + "video.js": "^5.3.0" } } diff --git a/src/videojs.ads.js b/src/videojs.ads.js index ed0471b2..15048c21 100644 --- a/src/videojs.ads.js +++ b/src/videojs.ads.js @@ -144,7 +144,8 @@ var suppressedTracks = [], snapshot = { ended: player.ended(), - src: player.currentSrc(), + currentSrc: player.currentSrc(), + src: player.src(), currentTime: player.currentTime(), type: player.currentType() }; @@ -295,24 +296,14 @@ var // ads, the content player state hasn't been modified and so no // restoration is required - if (player.src()) { - // the player was in src attribute mode before the ad and the - // src attribute has not been modified, no restoration is required - // to resume playback - srcChanged = player.src() !== snapshot.src; - } else { - // the player was configured through source element children - // and the currentSrc hasn't changed, no restoration is required - // to resume playback - srcChanged = player.currentSrc() !== snapshot.src; - } + srcChanged = player.src() !== snapshot.src || player.currentSrc() !== snapshot.currentSrc; if (srcChanged) { // on ios7, fiddling with textTracks too early will cause safari to crash player.one('contentloadedmetadata', restoreTracks); // if the src changed for ad playback, reset it - player.src({ src: snapshot.src, type: snapshot.type }); + player.src({ src: snapshot.currentSrc, type: snapshot.type }); // safari requires a call to `load` to pick up a changed source player.load(); // and then resume from the snapshots time once the original src has loaded @@ -406,7 +397,7 @@ var } else if (player.ads.state === 'content-resuming') { if (player.ads.snapshot) { // the video element was recycled for ad playback - if (player.currentSrc() !== player.ads.snapshot.src) { + if (player.currentSrc() !== player.ads.snapshot.currentSrc) { if (event.type === 'loadstart') { return; } @@ -449,7 +440,7 @@ var // This will allow ad-integrations from needing to do this themselves. player.on(['addurationchange', 'adcanplay'], function() { var snapshot = player.ads.snapshot; - if (player.currentSrc() === snapshot.src) { + if (player.currentSrc() === snapshot.currentSrc) { return; // do nothing } diff --git a/test/videojs.ads.snapshot.js b/test/videojs.ads.snapshot.js index 2f6757ba..fca5fbde 100644 --- a/test/videojs.ads.snapshot.js +++ b/test/videojs.ads.snapshot.js @@ -116,7 +116,7 @@ QUnit.test('only restores the player snapshot if the src changed', function(asse this.player.ads.startLinearAdMode(); this.player.ads.endLinearAdMode(); assert.ok(playSpy.called, 'content playback resumed'); - assert.ok(srcSpy.alwaysCalledWithExactly(), 'the src was reset'); + assert.ok(srcSpy.alwaysCalledWithExactly(), 'the src was not reset'); this.player.trigger('playing'); assert.ok(this.contentPlaybackSpy.calledOnce, 'A content-playback event should have triggered'); @@ -360,6 +360,9 @@ QUnit.test('checks for a src attribute change that isn\'t reflected in currentSr this.player.trigger('play'); this.player.ads.startLinearAdMode(); + // `src` gets called internally to set the source back to its original + // value when the player snapshot is restored when `endLinearAdMode` + // is called. this.player.src = function(source) { if (source === undefined) { return 'ad.mp4';