Problems adding preRolls to AdScheduler with await.

Topics: Windows 8 Xaml, Windows Phone 8
Sep 30, 2013 at 1:58 PM
Edited Sep 30, 2013 at 1:58 PM
Hey,
I've got a strange problem and it does not necessarily has its origin in the playerFramework, hence I hope someone here can help me.

I've got the following (shortened) code to collect my preRolls:
  foreach (var r in _preRolls)
        {
            dynamic roll = JObject.Parse(r.ToString());
            var preRoll = new PrerollAdvertisement();
            string server = (roll.server.tag).ToString();

            HttpClient client = new HttpClient();
            string str = __await__ client.GetStringAsync(new Uri(server));
            if (!(checkAdvertising(str)))
            {
               //set another preRollSource
            }
            else
            {
                preRoll.Source = new RemoteAdSource(new Uri(server), Microsoft.VideoAdvertising.VastAdPayloadHandler.AdType);
            }
            adScheduler.Advertisements.Add(preRoll);
  }
  //...
  player.play();

It results in starting to play the ad and after about 5 seconds, the ad freezes and the video starts playing (I only hear the sound of the video. The frozen image of the ad is still on screen)

I noticed, that this does not happen if I do not have the HttpClient getting the string with await.

Before the ad stops playing I have the following Output (it does not show up when I fill my adScheduler without having the 'await'-call in-between):
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Exception' occurred in Microsoft.VideoAdvertising.DLL
A first chance exception of type 'System.Exception' occurred in Microsoft.VideoAdvertising.DLL
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Exception' occurred in Microsoft.VideoAdvertising.DLL
A first chance exception of type 'System.Exception' occurred in Microsoft.VideoAdvertising.DLL
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll


Any idea? Is my approach of fetching information with await not possible?
Thanks in advance!
Coordinator
Sep 30, 2013 at 7:01 PM
You should be able to solve this by either:
1) Creating the prerolls before setting the source.
2) Setting AutoPlay = false and create prerolls before calling .Play()
3) Using the MediaLoading event and it's deferral to force the player to wait while you fetch and create your ads.

Our scheduling plugins (e.g. our VMAP plugin) uses approach #3. If it is helpful, you can check out the source code for the VMAP plugin here.