Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 5.3.x / fix srcChanged logic. #133

Merged
merged 4 commits into from
Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
21 changes: 6 additions & 15 deletions src/videojs.ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion test/videojs.ads.snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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';
Expand Down