Example #1
0
        /// <summary>
        /// Get ad URL and call to that.
        /// </summary>
        /// <returns></returns>
        private IEnumerator DoAdRequest()
        {
            string adNetworkUrl;

            if (m_wrapperList.Count > 0)
            {
                adNetworkUrl = m_wrapperList[m_wrapperList.Count - 1].VASTAdTagURI;
            }
            else
            {
                if (VSettings.PrerollAdProviders.Count > 0 && !VSettings.IsPreRollAdPlayed)
                {
                    adNetworkUrl = VSettings.PrerollAdProviders[m_adUrlIndex];
                }
                else if (VSettings.MidrollAdProviders.Count > 0)
                {
                    adNetworkUrl = VSettings.MidrollAdProviders[m_adUrlIndex];
                    m_isMidRoll  = true;
                }
                else
                {
                    Error("No ad providers", false);
                    yield break;
                }

                // Special treatment for URL containing value
                if (adNetworkUrl.Contains("<<<EXTRA>>>"))
                {
                    adNetworkUrl = adNetworkUrl.Replace("<<<EXTRA>>>", VUtils.GetTimestamp().ToString());
                    Debug.Log(adNetworkUrl);
                }
            }

            m_isWaitingResponse = true;
            if (!m_network.CallGet(adNetworkUrl, AdRequestCallback))
            {
                m_isWaitingResponse = false;
                Error("Call failed to " + adNetworkUrl, true);
                TryNext();
            }

            float timeOut = Time.realtimeSinceStartup + VSettings.BaseTimeOut;

            while (m_isWaitingResponse)
            {
                if (Time.realtimeSinceStartup > timeOut)
                {
                    m_isWaitingResponse = false;
                    Error("Ad loading timed out", true);
                    yield break;
                }
                yield return(null);
            }
        }
        /// <summary>
        /// Prepare song. Fetch source URL.
        /// </summary>
        /// <returns></returns>
        private IEnumerator PrepareSong()
        {
            if (m_currentSong == null)
            {
                OnError("No song specified");
                yield break;
            }

            OnLoading();

            m_isSongSourceLoaded = false;
            if (!m_network.CallGet(string.Concat(VStrings.APIV2, "genres/", m_currentSong.Playlist, "/musics/", m_currentSong.Id), SourceReceivedCallback))
            {
                m_network.CancelCalls();
                OnError("Can't get song source");
                yield break;
            }

            float timeOut = Time.realtimeSinceStartup + VSettings.BaseTimeOut;

            while (!m_isSongSourceLoaded)
            {
                if (Time.realtimeSinceStartup > timeOut)
                {
                    m_network.CancelCalls();
                    OnTimedOut();
                    StopAllCoroutines();
                    yield break;
                }
                yield return(null);
            }
        }
Example #3
0
 /// <summary>
 /// Call tracking URLs.
 /// </summary>
 /// <param name="ev"></param>
 /// <param name="urls"></param>
 private void TrackEvent(string ev, List <string> urls)
 {
     foreach (string url in urls)
     {
         m_network.CallGet(url, null);
     }
 }
Example #4
0
        private IEnumerator DownloadCatalogueAndSettings()
        {
            m_isWaitingResponse = true;

            if (!m_network.CallGet(VStrings.CATALOGUE, ProcessCatalogueCallback))
            {
                OnFinished(false, "error: could not download catalogue");
                yield break;
            }

            float timeOut = Time.realtimeSinceStartup + VSettings.BaseTimeOut;

            while (m_isWaitingResponse)
            {
                if (Time.realtimeSinceStartup > timeOut)
                {
                    m_isWaitingResponse = false;
                    m_network.CancelCalls();
                    OnFinished(false, "error: downloading catalogue timed out");
                    StopAllCoroutines();
                    yield break;
                }
                yield return(null);
            }
        }
Example #5
0
        /// <summary>
        /// Start ad playback
        /// </summary>
        /// <param name="clip"></param>
        private void StartPlayback(AudioClip clip)
        {
            DisposeCurrentAudio();

            if (m_isBannerTextureLoaded)
            {
                VPlayerController.Instance.SetAdBannerActive(true);
            }

            if (m_adContainsBanner && m_isBannerTextureLoaded)
            {
                m_currentAd.DoEventTracking(VStrings.Ad_CreativeView);
            }

            m_currentAd.DoEventTracking(VStrings.Ad_Start);

            if (m_currentAd != null && m_currentAd.GetImpressionUrls().Count > 0)
            {
                // Adswizz requires impression calls at start, other networks at completion
                if (m_currentAd.GetMediaUrl().Contains("adswizz"))
                {
                    foreach (var imprToCall in m_currentAd.GetImpressionUrls())
                    {
                        m_network.CallGet(imprToCall, null);
                    }
                }
            }
            else
            {
                OnError("Error calling impressions!");
            }

            m_isAdStarted = true;

            m_audioSource.clip = clip;
            m_audioSource.Play();

            OnStarted();
        }
Example #6
0
        /// <summary>
        /// Ad is completed. Continue with music playback.
        /// </summary>
        private void OnCompleted()
        {
            if (m_currentAd != null && m_currentAd.GetImpressionUrls().Count > 0)
            {
                foreach (var imprToCall in m_currentAd.GetImpressionUrls())
                {
                    m_network.CallGet(imprToCall, null);
                }
            }
            else
            {
                OnError("Error calling impressions!");
            }

            m_currentAd.DoEventTracking(VStrings.Ad_Complete);
            Reset();

            if (OnPlaybackCompleted != null)
            {
                OnPlaybackCompleted();
            }

            ChangeState(PlayerState.Standby);
        }