Esempio n. 1
0
        /// <summary>
        /// Ad playback has started. Update UI based on ad info.
        /// </summary>
        /// <param name="ad"></param>
        private void OnAdPlaybackStarted(VPlayableAd ad)
        {
            m_currentAd = ad;

            m_currentState.PlayingAd((m_currentAd.LinkText.Length > 3) ? VStrings.AdvertisementBuff : m_currentAd.LinkText);
            UpdatePlayerUI();
        }
Esempio n. 2
0
        /// <summary>
        /// Reset ad handler.
        /// </summary>
        public void Reset()
        {
            m_playableAd = null;
            m_wrapperList.Clear();

            m_isMidRoll         = false;
            m_isWaitingResponse = false;
            m_adUrlIndex        = 0;
            m_wrapperCount      = 0;
        }
Esempio n. 3
0
        /// <summary>
        /// AdHandler sent ad, preparations can be started.
        /// </summary>
        /// <param name="ad"></param>
        private void OnAdReady(VPlayableAd ad)
        {
            VPlayerController.Instance.SetSplashActive(false);
            m_currentAd = ad;

            if (m_currentAd == null)
            {
                OnError("Current ad is null");
                return;
            }

            StartCoroutine(PrepareAd(m_currentAd.GetMediaUrl()));
        }
Esempio n. 4
0
        /// <summary>
        /// Stop ad playback and get rid of it. Reset song counter.
        /// </summary>
        private void StopAdPlayback()
        {
            m_currentState.AdPlaybackStop();

            m_currentAd = null;
            VSettings.IsPreRollAdPlayed = true;

            RemoveAdPlaybackListeners();
            AddMusicPlaybackListeners();

            m_songCounter = 0;
            m_playAdNext  = false;

            Play();
        }
Esempio n. 5
0
        /// <summary>
        /// Disposes current ad and resets
        /// </summary>
        private void Reset()
        {
            m_adHandler.OnAdReady -= OnAdReady;
            m_adHandler.OnAdError -= OnAdError;
            m_audioSource.Stop();
            m_audioSource.clip = null;

            VPlayerController.Instance.SetAdBannerActive(false);

            m_adHandler.Reset();

            m_adRequested  = false;
            m_isAdPrepared = false;
            m_isAdStarted  = false;

            m_currentAd = null;
        }
Esempio n. 6
0
        /// <summary>
        /// Build ad
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        private IEnumerator BuildAdFromVast(VAST xml)
        {
            if (xml == null)
            {
                Error("Could not parse VAST", true);
                yield break;
            }

            if (xml.Ads == null)
            {
                Error("No ads in VAST or parsing failed", true);
                yield break;
            }

            foreach (var ad in xml.Ads)
            {
                if (ad.InLines != null)
                {
                    // if InLine, already playable ad
                    foreach (var inline in ad.InLines)
                    {
                        VPlayableAd parsedAd = ParseInline(inline);
                        if (m_wrapperList.Count > 0)
                        {
                            parsedAd.Wrappers.AddRange(m_wrapperList);
                        }
                        m_playableAd = parsedAd;
                        m_wrapperList.Clear();

                        yield return(null);
                    }
                }

                if (ad.Wrappers != null)
                {
                    // if wrapper, get more info from VASTAdTagURI
                    foreach (var wrapper in ad.Wrappers)
                    {
                        ExtractWrapper(wrapper);
                        yield break;
                    }
                }
            }

            Success();
        }
Esempio n. 7
0
        /// <summary>
        /// Get all the needed info for playable ad.
        /// </summary>
        /// <param name="inline"></param>
        /// <returns></returns>
        private VPlayableAd ParseInline(InLine inline)
        {
            VPlayableAd ad = new VPlayableAd();

            ad.AdSystem        = inline.AdSystem.Text;
            ad.AdSystemVersion = inline.AdSystem.Version;
            ad.AdTitle         = inline.AdTitle.Text;

            // add impressions
            for (int i = 0; i < inline.Impressions.Length; i++)
            {
                ad.Impressions.Add(i, inline.Impressions[i].URL);
            }

            // create creatives
            for (int i = 0; i < inline.Creatives.Creative.Length; i++)
            {
                VCreative vc = new VCreative();
                vc.ID       = inline.Creatives.Creative[i].Id;
                vc.Sequence = inline.Creatives.Creative[i].Sequence;

                if (inline.Creatives.Creative[i].LinearAds != null)
                {
                    foreach (var linear in inline.Creatives.Creative[i].LinearAds)
                    {
                        vc.Type = "Linear";
                        if (linear.SkipOffset != null)
                        {
                            vc.SkipOffset = linear.SkipOffset;
                            vc.Skippable  = true;
                        }
                        vc.Duration = linear.Duration;

                        if (linear.TrackingEvents != null)
                        {
                            // Get tracking events
                            Tracking[] tracking = linear.TrackingEvents.Tracking;
                            for (int j = 0; j < tracking.Length; j++)
                            {
                                if (vc.TrackingEvents.ContainsKey(tracking[j].EventType))
                                {
                                    vc.TrackingEvents[tracking[j].EventType].Add(tracking[j].EventURL);
                                }
                                else
                                {
                                    vc.TrackingEvents.Add(tracking[j].EventType, new List <string>()
                                    {
                                        tracking[j].EventURL
                                    });
                                }
                            }
                        }

                        if (linear.VideoClicks != null)
                        {
                            // Get click events
                            VideoClicks clicks = linear.VideoClicks;
                            if (clicks != null)
                            {
                                if (clicks.ClickThrough != null && !string.IsNullOrEmpty(clicks.ClickThrough.Text))
                                {
                                    vc.VideoClicks.Add(VStrings.Ad_ClickThrough, clicks.ClickThrough.Text);
                                }
                                if (clicks.ClickTracking != null && !string.IsNullOrEmpty(clicks.ClickTracking.Text))
                                {
                                    vc.VideoClicks.Add(VStrings.Ad_ClickTracking, clicks.ClickTracking.Text);
                                }
                                if (clicks.CustomClick != null && !string.IsNullOrEmpty(clicks.CustomClick.Text))
                                {
                                    vc.VideoClicks.Add(VStrings.Ad_CustomClick, clicks.CustomClick.Text);
                                }
                            }
                        }

                        if (linear.MediaFiles != null)
                        {
                            // Get playable media file
                            MediaFile[] media = linear.MediaFiles.MediaFile;
                            if (media != null)
                            {
                                for (int j = 0; j < media.Length; j++)
                                {
                                    vc.MediaFiles.Add(media[j].MimeType, media[j].MediaUrl.Trim());
                                }
                            }
                        }
                    }
                }
                else if (inline.Creatives.Creative[i].NonLinearAds != null)
                {
                    vc.Type = "NonLinear";
                    Debug.Log("NonLinearAds are not supported");
                }
                else if (inline.Creatives.Creative[i].CompanionAds != null && !m_isMidRoll)
                {
                    vc.Type = "CompanionAd";

                    // TODO: calculate space for banner based on image size in UI
                    Companion companion = FindSuitableCompanion(inline.Creatives.Creative[i].CompanionAds, 300, 250);
                    if (companion != null)
                    {
                        vc.StaticImageUrl        = companion.StaticResourceURL.Text;
                        vc.CompanionClickThrough = companion.ClickThrough.Text;

                        // get creative view events
                        if (companion.TrackingEvents != null && companion.TrackingEvents.Tracking.Length > 0)
                        {
                            for (int j = 0; j < companion.TrackingEvents.Tracking.Length; j++)
                            {
                                if (vc.TrackingEvents.ContainsKey(companion.TrackingEvents.Tracking[j].EventType))
                                {
                                    vc.TrackingEvents[companion.TrackingEvents.Tracking[j].EventType].Add(companion.TrackingEvents.Tracking[j].EventURL);
                                }
                                else
                                {
                                    vc.TrackingEvents.Add(companion.TrackingEvents.Tracking[j].EventType, new List <string>()
                                    {
                                        companion.TrackingEvents.Tracking[j].EventURL
                                    });
                                }
                            }
                        }
                    }
                }

                ad.Creatives.Add(vc);
            }

            if (inline.Extensions != null && inline.Extensions.Extension != null)
            {
                if (inline.Extensions.Extension.Length > 0)
                {
                    for (int i = 0; i < inline.Extensions.Extension.Length; i++)
                    {
                        ad.Extensions.Add(inline.Extensions.Extension[i].Type, inline.Extensions.Extension[i].Value);
                    }
                }
            }

            return(ad);
        }