Ejemplo n.º 1
0
        /// <summary>
        /// Removes the ad.
        /// </summary>
        /// <param name="ad">The ad creative that should be removed.</param>
        public void RemoveAd(ActiveCreative ad)
        {
            ad.Target.RemoveChild(ad.Player);
            UnhookPlayer(ad.Player);
            activeAds.Remove(ad.Player);

            if (ad.Player is IDisposable)
            {
                try
                {
                    ((IDisposable)ad.Player).Dispose();
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.Dispose Exception: " + ex.Message));
                }
            }

            var userState = userStates[ad];

            userStates.Remove(ad);

            if (AdRemoved != null)
            {
                AdRemoved(this, new ActiveCreativeEventArgs(ad, userState));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads a creative. This causes VPAID.InitAd to execute.
        /// </summary>
        /// <param name="ad">The creative to load</param>
        /// <param name="bitrate">The current bitrate of the player. This is passed onto the VPAID player which can use it to initialize itself.</param>
        /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
        public void LoadAd(ActiveCreative ad, int bitrate, object userState)
        {
            if (!activeAds.ContainsKey(ad.Player))
            {
                activeAds.Add(ad.Player, ad);
                HookupPlayer(ad.Player);
            }

            userStates.Add(ad, userState);

            Size adContainerSize = ad.Target.Size;

            TimeoutHelper <EventArgs> InitAdTimeoutHandler = new TimeoutHelper <EventArgs>();

            ad.Player.AdLoaded += InitAdTimeoutHandler.Complete;
            EventHandler <VpaidMessageEventArgs> failHandler = (s, e) => InitAdTimeoutHandler.Failed(new Exception(e.Message));

            ad.Player.AdError -= player_AdError;
            ad.Player.AdError += failHandler;

            InitAdTimeoutHandler.Completed += (s, e) =>
            {
                ad.Player.AdLoaded -= InitAdTimeoutHandler.Complete;
                ad.Player.AdError  -= failHandler;
                if (e.Error == null)
                {
                    ad.Player.AdError += player_AdError;
                    player_AdLoaded(ad.Player, e.Result);
                }
                else
                if (AdLoadFailed != null)
                {
                    AdLoadFailed(this, new ActiveCreativeEventArgs(ad, userState));
                }
            };
            InitAdTimeoutHandler.Begin(() =>
            {
                try
                {
                    ad.Player.InitAd(
                        adContainerSize.Width,
                        adContainerSize.Height,
#if !WINDOWS_PHONE && !FULLSCREEN
                        Application.Current.Host.Content.IsFullScreen ? "fullscreen" : "normal",
#else
                        "normal",
#endif
                        bitrate,
                        ad.Source.MediaSource,
                        ad.Source.ExtraInfo);
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.AdInit Exception: " + ex.Message));
                    throw ex;
                }
            }, AdInitTimeout);
        }
        protected void CancelCreative(ActiveCreative creative)
        {
            VpaidController.RemoveAd(creative);

            if (CreativeCanceled != null)
            {
                CreativeCanceled(this, new CreativeEventArgs(creative.Source));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Passes on player volume to a single ad
        /// </summary>
        /// <param name="VolumeLevel"></param>
        public void SetVolume(ActiveCreative activeCreative, double VolumeLevel)
        {
            uint vPaidVolume = (uint)(VolumeLevel * 100);

            try
            {
                activeCreative.Player.AdVolume = vPaidVolume;
            }
            catch (Exception ex)
            {
                OnLog(new ActiveCreativeLogEventArgs(activeCreative, "VPAID.AdVolume.Set Exception: " + ex.Message));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Stops the ad.
        /// </summary>
        /// <param name="ad">The ad creative that should stop playing</param>
        /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
        void StopAd(ActiveCreative ad, object userState)
        {
            TimeoutHelper <EventArgs> timeoutHandler = new TimeoutHelper <EventArgs>();

            ad.Player.AdStopped -= player_AdStopped;    // temporarily unhook this event. Instead we will use our timeout handler to help trap for it.
            ad.Player.AdStopped += timeoutHandler.Complete;
            EventHandler <VpaidMessageEventArgs> failHandler = (s, e) => timeoutHandler.Failed(new Exception(e.Message));

            ad.Player.AdError        -= player_AdError;
            ad.Player.AdError        += failHandler;
            timeoutHandler.Completed += (s, e) =>
            {
                ad.Player.AdStopped += player_AdStopped;    // hook up the event again
                ad.Player.AdStopped -= timeoutHandler.Complete;
                ad.Player.AdError   -= failHandler;
                if (e.Error == null)
                {
                    ad.Player.AdError += player_AdError;
                    player_AdStopped(ad.Player, e.Result);
                }
                else
                if (AdStopFailed != null)
                {
                    AdStopFailed(this, new ActiveCreativeEventArgs(ad, userState));
                }
            };
            timeoutHandler.Begin(() =>
            {
                try
                {
                    ad.Player.StopAd();
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.StopAd Exception: " + ex.Message));
                    throw ex;
                }
            }, AdStopTimeout);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Tells the ad to start.
        /// </summary>
        /// <param name="ad">The ad creative that should start playing</param>
        /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
        public void StartAd(ActiveCreative ad, object userState)
        {
            TimeoutHelper <EventArgs> timeoutHandler = new TimeoutHelper <EventArgs>();

            ad.Player.AdStarted += timeoutHandler.Complete;
            EventHandler <VpaidMessageEventArgs> failHandler = (s, e) => timeoutHandler.Failed(new Exception(e.Message));

            ad.Player.AdError        -= player_AdError;
            ad.Player.AdError        += failHandler;
            timeoutHandler.Completed += (s, e) =>
            {
                ad.Player.AdStarted -= timeoutHandler.Complete;
                ad.Player.AdError   -= failHandler;
                if (e.Error == null)
                {
                    ad.Player.AdError += player_AdError;
                    player_AdStarted(ad.Player, e.Result);
                }
                else
                if (AdStartFailed != null)
                {
                    AdStartFailed(this, new ActiveCreativeEventArgs(ad, userState));
                }
            };
            timeoutHandler.Begin(() =>
            {
                try
                {
                    ad.Player.StartAd();
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.StartAd Exception: " + ex.Message));
                    throw ex;
                }
            }, AdStartTimeout);
        }
 /// <summary>
 /// Passes on player volume to a single ad
 /// </summary>
 /// <param name="VolumeLevel"></param>
 public void SetVolume(ActiveCreative activeCreative, double VolumeLevel)
 {
     uint vPaidVolume = (uint)(VolumeLevel * 100);
     try
     {
         activeCreative.Player.AdVolume = vPaidVolume;
     }
     catch (Exception ex)
     {
         OnLog(new ActiveCreativeLogEventArgs(activeCreative, "VPAID.AdVolume.Set Exception: " + ex.Message));
     }
 }
 internal ActiveCreativeEventArgs(ActiveCreative ActiveCreative, object UserState)
 {
     activeCreative = ActiveCreative;
     userState = UserState;
 }
 internal ActiveCreativeLogEventArgs(ActiveCreative ActiveCreative, string Message)
 {
     activeCreative = ActiveCreative;
     message = Message;
 }
 internal ActiveCreativeEventArgs(ActiveCreative ActiveCreative, object UserState)
 {
     activeCreative = ActiveCreative;
     userState      = UserState;
 }
 internal ActiveCreativeLogEventArgs(ActiveCreative ActiveCreative, string Message)
 {
     activeCreative = ActiveCreative;
     message        = Message;
 }
 /// <summary>
 /// Stops the ad.
 /// </summary>
 /// <param name="ad">The ad creative that should stop playing</param>
 /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
 void StopAd(ActiveCreative ad, object userState)
 {
     TimeoutHelper<EventArgs> timeoutHandler = new TimeoutHelper<EventArgs>();
     ad.Player.AdStopped -= player_AdStopped;    // temporarily unhook this event. Instead we will use our timeout handler to help trap for it.
     ad.Player.AdStopped += timeoutHandler.Complete;
     EventHandler<VpaidMessageEventArgs> failHandler = (s, e) => timeoutHandler.Failed(new Exception(e.Message));
     ad.Player.AdError -= player_AdError;
     ad.Player.AdError += failHandler;
     timeoutHandler.Completed += (s, e) =>
     {
         ad.Player.AdStopped += player_AdStopped;    // hook up the event again
         ad.Player.AdStopped -= timeoutHandler.Complete;
         ad.Player.AdError -= failHandler;
         if (e.Error == null)
         {
             ad.Player.AdError += player_AdError;
             player_AdStopped(ad.Player, e.Result);
         }
         else
             if (AdStopFailed != null) AdStopFailed(this, new ActiveCreativeEventArgs(ad, userState));
     };
     timeoutHandler.Begin(() =>
     {
         try
         {
             ad.Player.StopAd();
         }
         catch (Exception ex)
         {
             OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.StopAd Exception: " + ex.Message));
             throw ex;
         }
     }, AdStopTimeout);
 }
 protected void PlayCreative(ActiveCreative creative, object userState)
 {
     VpaidController.LoadAd(creative, (int)(adHost.PlaybackBitrate / 1024), userState);
     RefreshAdMode();
 }
        /// <summary>
        /// Loads a creative. This causes VPAID.InitAd to execute.
        /// </summary>
        /// <param name="ad">The creative to load</param>
        /// <param name="bitrate">The current bitrate of the player. This is passed onto the VPAID player which can use it to initialize itself.</param>
        /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
        public void LoadAd(ActiveCreative ad, int bitrate, object userState)
        {
            if (!activeAds.ContainsKey(ad.Player))
            {
                activeAds.Add(ad.Player, ad);
                HookupPlayer(ad.Player);
            }

            userStates.Add(ad, userState);

            Size adContainerSize = ad.Target.Size;

            TimeoutHelper<EventArgs> InitAdTimeoutHandler = new TimeoutHelper<EventArgs>();
            ad.Player.AdLoaded += InitAdTimeoutHandler.Complete;
            EventHandler<VpaidMessageEventArgs> failHandler = (s, e) => InitAdTimeoutHandler.Failed(new Exception(e.Message));
            ad.Player.AdError -= player_AdError;
            ad.Player.AdError += failHandler;

            InitAdTimeoutHandler.Completed += (s, e) =>
                {
                    ad.Player.AdLoaded -= InitAdTimeoutHandler.Complete;
                    ad.Player.AdError -= failHandler;
                    if (e.Error == null)
                    {
                        ad.Player.AdError += player_AdError;
                        player_AdLoaded(ad.Player, e.Result);
                    }
                    else
                        if (AdLoadFailed != null) AdLoadFailed(this, new ActiveCreativeEventArgs(ad, userState));
                };
            InitAdTimeoutHandler.Begin(() =>
            {
                try
                {
                    ad.Player.InitAd(
                        adContainerSize.Width,
                        adContainerSize.Height,
#if !WINDOWS_PHONE && !FULLSCREEN
                        Application.Current.Host.Content.IsFullScreen ? "fullscreen" : "normal",
#else
 "normal",
#endif
 bitrate,
                        ad.Source.MediaSource,
                        ad.Source.ExtraInfo);
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.AdInit Exception: " + ex.Message));
                    throw ex;
                }
            }, AdInitTimeout);
        }
        protected void CancelCreative(ActiveCreative creative)
        {
            VpaidController.RemoveAd(creative);

            if (CreativeCanceled != null)
                CreativeCanceled(this, new CreativeEventArgs(creative.Source));
        }
 /// <summary>
 /// Tells the ad to start.
 /// </summary>
 /// <param name="ad">The ad creative that should start playing</param>
 /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
 public void StartAd(ActiveCreative ad, object userState)
 {
     TimeoutHelper<EventArgs> timeoutHandler = new TimeoutHelper<EventArgs>();
     ad.Player.AdStarted += timeoutHandler.Complete;
     EventHandler<VpaidMessageEventArgs> failHandler = (s, e) => timeoutHandler.Failed(new Exception(e.Message));
     ad.Player.AdError -= player_AdError;
     ad.Player.AdError += failHandler;
     timeoutHandler.Completed += (s, e) =>
     {
         ad.Player.AdStarted -= timeoutHandler.Complete;
         ad.Player.AdError -= failHandler;
         if (e.Error == null)
         {
             ad.Player.AdError += player_AdError;
             player_AdStarted(ad.Player, e.Result);
         }
         else
             if (AdStartFailed != null) AdStartFailed(this, new ActiveCreativeEventArgs(ad, userState));
     };
     timeoutHandler.Begin(() =>
     {
         try
         {
             ad.Player.StartAd();
         }
         catch (Exception ex)
         {
             OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.StartAd Exception: " + ex.Message));
             throw ex;
         }
     }, AdStartTimeout);
 }
Ejemplo n.º 17
0
 public void PreloadAd(ActiveCreative ad, int bitrate)
 {
     if (ad.Player is IVpaidSupportsPreloading)
     {
         Size adContainerSize = ad.Target.Size;
         ((IVpaidSupportsPreloading)ad.Player).PreloadAd(
         adContainerSize.Width,
         adContainerSize.Height,
     #if !WINDOWS_PHONE && !FULLSCREEN
      Application.Current.Host.Content.IsFullScreen ? "fullscreen" : "normal",
     #else
      "normal",
     #endif
      bitrate,
         ad.Source.MediaSource,
         ad.Source.ExtraInfo,
         CurrentlyPlayingAdContext);
     }
 }
        /// <summary>
        /// Removes the ad.
        /// </summary>
        /// <param name="ad">The ad creative that should be removed.</param>
        public void RemoveAd(ActiveCreative ad)
        {
            ad.Target.RemoveChild(ad.Player);
            UnhookPlayer(ad.Player);
            activeAds.Remove(ad.Player);

            if (ad.Player is IDisposable)
            {
                try
                {
                    ((IDisposable)ad.Player).Dispose();
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.Dispose Exception: " + ex.Message));
                }
            }

            var userState = userStates[ad];
            userStates.Remove(ad);

            if (AdRemoved != null)
                AdRemoved(this, new ActiveCreativeEventArgs(ad, userState));
        }
 protected void PlayCreative(ActiveCreative creative, object userState)
 {
     VpaidController.LoadAd(creative, (int)(adHost.PlaybackBitrate / 1024), userState);
     RefreshAdMode();
 }