Suggested way to switch asset for playback?

Topics: Windows 8 JavaScript
Sep 20, 2012 at 4:35 PM

Hey guys, I'm looking for basically a way to shut down my current playback session and start another.  The simplest way would of course be to set the source property and start playback on that.

However, I have ads in the mix.  I'm not sure how to go about stopping ad playback.  If I just try to play an ad while a current one is playing, it seems the request is attempted ignored and comes back "done".

If I call dispose, it would seem that I just can't use the player anymore for the new playback session because it's been properly destroyed.

So, assuming I have ads, and I'm either playing an ad or not when I hit my "load new asset" button... What's the best way to clean things up/stop them, and start a fresh new session?  Is there an adHandlerPlugin.stop() method I'm not aware of?  Or even a mediaplayer.stop() method to cancel the entire playback session including ads?

thanks

Coordinator
Sep 20, 2012 at 5:54 PM

You should be able to call adHandlerPlugin.cancelActiveAds() before loading a new source to cancel any current ads.

Tim

Sep 20, 2012 at 6:56 PM

Thanks I actually tried that after looking at the source a little and finding the method.  It seemed to have absolutely no effect.  Is that supposed to work on an ad that is playing, not scheduled, and launched just with playAd(adsource)?

When I step through it looks like it calls cancelActiveAds on the controller, but stepping through one more time, I'm suddenly in the VpaidAdapter on _onGetAdLinearRequested, it sets e.result to true (from the adLinear property), and then exits all of the functions.

I'm not sure quite what it's trying to do here, but as it didn't do anything prior to your response, I just assumed it was a dead end.

Developer
Sep 20, 2012 at 10:20 PM

hi ben,

You are right about cancelActiveAds. It doesn't seem to do much. I will look into it further.

As far as resetting/reloading a new source while ads are playing, this code works great in the newest drop of MMPPF (to be released this afternoon!).

var loadButton = element.querySelector("#loadButton");
var stopButton = element.querySelector("#stopButton");
var newSrc = "http://smf.blob.core.windows.net/samples/videos/wildlife.mp4";

loadButton.onclick = function (e) {
    // mediaPlayer.adHandlerPlugin.cancelActiveAds(); <-- not doing much :(
    // this works great, however! :)
    if (mediaPlayer.src !== newSrc) {
        mediaPlayer.src = newSrc;
    } else {
        mediaPlayer.load();
    }
};

stopButton.onclick = function (e) {
    mediaPlayer.src = null;
};

Thanks!

Developer
Sep 20, 2012 at 10:23 PM

OK, it looks like cancelActiveAds is only used to cancel nonlinear ads and is called internally when the next ad shows up, so it should not have been exposed as such. We will look into exposing a more suitable API along these lines. For now, please forget you ever saw that method and refer to the reload/reset code I posted above. Thanks!

Sep 24, 2012 at 5:05 PM

Hey, trying Preview 6 right now, and unfortunately I'm not seeing an improvement.  

When I set the source to null during playback of the main asset, it does work.  However if I do it when my preroll is playing (it's a custom programmed ad, so not a TRUE preroll), the video goes dark, but the audio of my ad is still playing.

Doing mp.load() after setting the source seems to ALSO work fine, but only if my main asset is playing.  If it's my preroll that's playing when I do this, it seems to attempt playback on my preroll again, but it can't and it triggers the ad complete event right away.  Meanwhile, my preroll's audio is still playing while my custom code sees that the ad is finished, so I go ahead and unpause the main content.

So, it looks like the common thread here is that I can't cancel/stop the ad playback.  Perhaps there's some way to reach in and do so?

Sep 24, 2012 at 5:27 PM

Oh, I didn't see the error output, since it wasn't crashing the entire app.  This is what happens when I reset the source and do a load:

'WWAHost.exe' (Script): Loaded 'Script Code (MSAppHost/1.0)'. Exception was thrown at line 1950, column 33 in ms-appx://fad2f94b-ba56-4bb5-8dda-d432170104aa/Microsoft.PlayerFramework.Js/js/PlayerFramework.js0x80004005 - JavaScript runtime error: Unspecified error.Exception was thrown at line 227, column 5 in Function code0x80131500 - JavaScript runtime error: System.Exception   at Microsoft.VideoAdvertising.AdHandlerController.<PlayAdAsync>d__16.MoveNext()--- End of stack trace from previous location where exception was thrown ---   at System.Threading.Tasks.TaskToAsyncInfoAdapter`4.GetResultsInternal()WinRT information: Ad in progress and cannot be canceled.Exception was thrown at line 227, column 5 in Function code0x80131500 - JavaScript runtime error: System.Exception   at Microsoft.VideoAdvertising.AdHandlerController.<PlayAdAsync>d__16.MoveNext()--- End of stack trace from previous location where exception was thrown ---   at System.Threading.Tasks.TaskToAsyncInfoAdapter`4.GetResultsInternal()WinRT information: Ad in progress and cannot be canceled.The program '[1640] WWAHost.exe' has exited with code -1 (0xffffffff).

 

And this is what happens when I simply set the source to null:

'WWAHost.exe' (Script): Loaded 'Script Code (MSAppHost/1.0)'. Exception was thrown at line 1950, column 33 in ms-appx://fad2f94b-ba56-4bb5-8dda-d432170104aa/Microsoft.PlayerFramework.Js/js/PlayerFramework.js0x80004005 - JavaScript runtime error: Unspecified error.The program '[3604] WWAHost.exe' has exited with code -1 (0xffffffff).