This project is read-only.

Problem playing ads with custom plugin

Topics: Windows 8 JavaScript
Sep 12, 2013 at 1:00 AM

I'm working on a plugin for HLS and I'm running into some problems when playing ads.
I created a JS project and added the player in there. I scheduled some preroll and midroll but only midrolls play and when they play the main video doesn't pause.

Do you have any ideas on why prerolls might not be playing and how to handle and pause when a midroll starts playing?

Thank you,
Sep 12, 2013 at 10:03 PM
Edited Sep 12, 2013 at 10:03 PM
After a bit of debugging I found that the part where the advertising plugin does pauses the player before the ad plays isn't executing properly.
// pause the media player if we're loading an ad or playing a linear ad
if (this.mediaPlayer.playerState === PlayerFramework.PlayerState.started) {
    if ((newState === Microsoft.VideoAdvertising.AdState.loading || newState === Microsoft.VideoAdvertising.AdState.linear) && (oldState === Microsoft.VideoAdvertising.AdState.none || oldState === Microsoft.VideoAdvertising.AdState.nonLinear)) {
    } else if ((oldState === Microsoft.VideoAdvertising.AdState.loading || oldState === Microsoft.VideoAdvertising.AdState.linear) && (newState === Microsoft.VideoAdvertising.AdState.none || newState === Microsoft.VideoAdvertising.AdState.nonLinear)) {;
In that first if, the mediaPlayer.playerState is 4 (opened) instead of 6 (started) but the video is playing. Do you know what might be causing the playerState to be "opened" instead of "started" ?

Thank you.
Sep 13, 2013 at 1:07 AM
If I had to guess, I'd guess that there is something wrong with your HLS plugin/media extension that causes autoplay=false not to work properly. Internally, we always force autoplay=false on the video tag, then call .play() (this is needed for prerolls... even if you aren't using them and even if you set mediaPlayer.autoplay = true).

You may want to try setting a breakpoint on the line of code in the player framework's .js file that sets this.playerState = PlayerFramework.PlayerState.started to see if it's hit. Hopefully this will shed some light on the issue.
Sep 13, 2013 at 2:11 AM
Thank you Tim.

My code was as follows:
<div id="vid" data-win-control="PlayerFramework.MediaPlayer">
  <video id="videoplayer" autoplay></video>
And with this configuration the started was being set before the opened.
Changing it to:
<div id="vid" data-win-control="PlayerFramework.MediaPlayer" data-win-options="{autoplay: true}">
  <video id="videoplayer"></video>
Fixed the problems with the ads.
With this configuration the opened is now set before the started.

I have another problem now where it fails to play the video sometimes but that's unrelated to the question.

Thank you again for your help.