protected void PausePlayback() { Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Collapsed); if (((Microsoft.SilverlightMediaFramework.Core.SMFPlayer)adHost).IsPlayBlocked) { // if we're already blocked, stick with it. AdHost.AddPlayBlock(this); isBlocking = true; } else { Player.ActiveMediaPlugin.Pause(); } }
protected override bool ExecutePayload(IAsyncAdPayload Payload, IAdSource Source) { var result = Payload as VastAdUnit; var adPod = result.AdPod; bool needsRelease; Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Collapsed); if (((Microsoft.SilverlightMediaFramework.Core.SMFPlayer)adHost).IsPlayBlocked) { // if we're already blocked, stick with it. AdHost.AddPlayBlock(loadBlocker); needsRelease = true; } else { Player.ActiveMediaPlugin.Pause(); needsRelease = false; } adPod.LoadAsync(success => { Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Visible); if (success) { // now that it is loaded, watch for each vastAd and CreativeSet to begin and complete running foreach (var vastAd in adPod.Ads) { vastAd.RunCompleted += vastAd_RunCompleted; foreach (var creativeSet in vastAd.CreativeSets) { creativeSet.RunStarting += creativeSet_RunStarting; creativeSet.RunStarted += creativeSet_RunStarted; creativeSet.RunCompleted += creativeSet_RunCompleted; } } // pass on that we are now running this ad. Note: It still could fail to run. result.OnStart(); // actually run the ad adPod.RunCompleted += new Action <AdPod, bool>(adPod_RunCompleted); adPod.ReleasePlayer += new Action <AdPod>(adPod_ReleasePlayer); adPod.RunAsync(); } else { // clear out the current running AdSpot. This permits other ads to be handled. activeCreativeSets.Clear(); activeAdPod = null; // notify upstream result.OnFail(); result.Deactivate(); base.ExecuteAdFailed(Source); if (!needsRelease) { Player.ActiveMediaPlugin.Play(); } } if (needsRelease) { adHost.ReleasePlayBlock(loadBlocker); } }); return(true); }