Skip to content

Commit

Permalink
Auto-play ads in same-video usecase.
Browse files Browse the repository at this point in the history
Resume on contentcanplay.
We now auto-play when an ad gets loaded if we're playing ads in the same video element as the content.
The problem is that in IE11, we cannot play in addurationchange but in iOS8, we cannot play from adcanplay.
This will allow ad-integrations from needing to do this themselves.
  • Loading branch information
gkatsev committed Mar 12, 2015
1 parent 397a918 commit eb57aba
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/videojs.ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ var
// 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
player.one('contentloadedmetadata', tryToResume);
player.one('contentcanplay', tryToResume);
} else if (!player.ended() || !snapshot.ended) {
// if we didn't change the src, just restore the tracks
restoreTracks();
Expand Down Expand Up @@ -430,6 +430,18 @@ var
return redispatch;
})();

// We now auto-play when an ad gets loaded if we're playing ads in the same video element as the content.
// The problem is that in IE11, we cannot play in addurationchange but in iOS8, we cannot play from adcanplay.
// This will allow ad-integrations from needing to do this themselves.
player.on(['addurationchange', 'adcanplay'], function(event) {
var snapshot = player.ads.snapshot;
if (player.currentSrc() === snapshot.src) {
return; // do nothing
}

player.play();
});

// replace the ad initializer with the ad namespace
player.ads = {
state: 'content-set',
Expand Down

5 comments on commit eb57aba

@waster
Copy link

@waster waster commented on eb57aba Mar 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that contentcanplay breaks resuming to play m3u8 at least after ad was played if m3u8 was without autoplay.

@dmlap
Copy link
Member

@dmlap dmlap commented on eb57aba Mar 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waster using native HLS or contrib-hls? Would you mind filing an issue so we can track it better?

@waster
Copy link

@waster waster commented on eb57aba Mar 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually using external flashhls plugin for videojs and see that canplay event didn't fire , I'll check with contrib-hls too.

@gkatsev
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. can we move this into an issue if this is an actual issue rather than a commit comment?
  2. what version of contrib-ads are you using?

@waster
Copy link

@waster waster commented on eb57aba Mar 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, opened the issue.

Please sign in to comment.