Pause Ad after Clickthrough

Topics: Windows 8 Xaml
Jun 20, 2013 at 9:47 AM
Edited Jun 20, 2013 at 9:53 AM
Hello everyone,

I'm using the player framework for displaying linear VAST ads. I use VAST 1 and 2 and because the framework only supports VAST 2 and 3 I have some own code that handles VAST 1.
For example, when clicking on the player while an ad is shown, the ad gets paused. Then there's a popup that asks if it's ok to open the ad's website in an external window (user's default browser). Clicking cancel will remove the popup and resume the ad. Clicking ok will open the website in the user's default browser and also fire some tracking requests. When returning from the browser the player resumes with the ad.

Now, the player framework does open the user's default browser and also fires tracking requests, but it doesn't pause the video.

In my code I register for the player.Tapped event and the first thing I do is player.Pause(). But this doesn't seem to work (for VAST 2 ads where the framework handles the ad).
Also, I can't find the handling of the Tapped event in the player framework source code.

I had a look at the player framework samples, more specifically the programmatic ad sample (https://playerframework.codeplex.com/SourceControl/latest#Win8.Xaml.Samples/Advertising/ProgrammaticAdPage.xaml.cs).
The ad doesn't get paused when clicking on it (btw. the clickthrough url is to some hotel chain while the ad is for Xbox). So in the line before PlayAd() gets called I added "player.Tapped += player_Tapped;" and in the class:
void player_Tapped(object sender, TappedRoutedEventArgs e)
{
    player.Pause();
}
This leads to a strange behaviour: When the app is active the video is indeed paused. But when it's in the background and the browser is in the foreground, the ad and the video resume playing. When bringing the app to the foreground again, the ad / video stops again.

So:

How do I pause an ad that gets played by the player framework while the user is in his browser because the player framework opened it for him?

Thanks in advance!
Coordinator
Jun 20, 2013 at 3:58 PM
To pause and resume the active media (ad or main content) use these APIs:
MediaPlayer.InteractiveViewModel.Pause();
MediaPlayer.InteractiveViewModel.PlayResume();
(I can explain more about why this works if you're interested).

To get the ad to pause when the ad is clicked and resume when the user returns, one option is to use the app suspend and resume callbacks. The app will automatically suspend when it goes to the background (when the ad is clicked) and resume when it comes back to the foreground. Note: if debugging from VS apps do not suspend unless you manually suspend the app from VS.

Hopefully this helps, let me know if you have more questions,

Tim
Jun 21, 2013 at 10:50 AM
Edited Jun 21, 2013 at 12:38 PM
Thanks for the quick reply Tim! It helped a lot!

Pausing now works when the user taps on the ad. I have two more questions though:

1) How can I change the behavior so that the website only gets opened after he chose to do so in a MessageDialog? This works in the VAST 1 case where I launch the URL myself in the Tapped event handler.

2) Resuming to play the ad by clicking the play button is fine instead of at app resume. But what I did with VAST 1 and what works is: Deactivated all controls for the ad. When the user clicks and the website gets opened I activate the controls. When the user clicks play to resume the ad I deactivate the controls again. I did this with the event handler for player.CurrentStateChanged. This event doesn't get fired in the case of VAST 2, so I changed it to player.InteractiveViewModel.CurrentStateChanged. But that event gets fired before the user clicks on play, so the controls never appear to be activated to the user. Why is that and what other ways are there to determine if the user clicked play?
Jul 11, 2013 at 9:59 PM
Edited Jul 11, 2013 at 10:40 PM
Hi again,

I'm not sure why last time the player.InteractiveViewModel.CurrentStateChanged event fired before it was supposed to do so, but now this seems to work.

But the other problem still exists (changing the behavior when the user clicks on a VAST 2 linear video ad).

I first solved it dirty with setting the clickthrough URL to null in the Player Framework Code (AdHost.cs), so the PF wouldn't launch and then I had to get the URL to launch it myself via a very long detour:
var ClickThroughUri = ((CreativeLinear)((AdDocumentPayload)adSchedulerPlugin.Advertisements[0].Source.Payload).AdPods[0].Ads[0].Creatives[0]).ClickThrough;
I changed this to do everything in single steps with checking for null etc. But it was still ugly and also I soon realized I had to do something similar with the ClickTracking URLs as well, not just ClickThrough, because the PF fires the tracking URLs before the user clicks on the "open browser" dialog I mentioned before and also when the user returns from an ad, which is paused at that time, and he clicks on the player to make the play button reappear, the tracking URLs get fired as well.

What I thought I could do then instead of the ugly things above was registering for the event myself (ActiveAdPlayer_AdClickThru), which you can access via the player. I found out the clickthrough URL even is available in the event args, so that was really useful. Then I commented out the registering of the event handler in AdHost.cs:
activeAdPlayer.AdClickThru += Vpaid_AdClickThru;
This didn't help though. Turns out the HyperlinkButton that's overlayed on the player has its own life and the only way to stop it from launching the URI really seems to be to set the NavigateUri to null in the ClickThroughButton_Click event. Not at another place, because this way I still get the URL delivered to my own event handler (the above mentioned ActiveAdPlayer_AdClickThru).

And now I'm stuck with the clicktracking URLs. The last event handler that gets called where they get handled (or at least read) is player_AdClickThru in VpaidController.cs.
The URLs aren't in the event args of the mentioned ActiveAdPlayer_AdClickThru and there doesn't seem to be an easy way to access the VpaidController via the player which is pretty much the only thing I have access to from outside the PF. And if I had access to the VpaidController the activeAds would still be private. I could just make it public in the source code, but I don't want to mess around in it in so many different places (makes it hard to update to new PF versions).

So again it boils down to this: How can you alter the behavior when the user interacts with an ad in general (best practice / without changing lots of code in lots of different places) and how can you fix my problem in particular (getting the clicktracking urls and maybe also changing the HyperLinkButton behavior)?

Thanks in advance!

P.S.: Also I can't find any UML diagrams or anything similar that would make it easier to find ones way through the source code.