Ejemplo n.º 1
0
		// ==============================================================================

		void RandomAdCallback(VreoResponse response)
		{
			if (response == null)
			{
				return;
			}
			// update local response reference for external access
			CurrentVreoResponse = response;

			if (response.success)
			{
				if (!string.IsNullOrEmpty(response.result.str_MediaURL))
				{
					if (response.result.str_MediaURL.ToLower().StartsWith("http"))
					{
						StartCoroutine(DownloadAdMediaAndLoad(response));
					}
					else
					{
						StartCoroutine(RetrieveStreamingAsset(response));
					}
				}
			}
			else
			{
				StartCoroutine(RetrieveStreamingAsset(response));
			}
		}
Ejemplo n.º 2
0
        IEnumerator RequestAd(VreoAdCanvas.MediaType mediaType, VreoAdCanvas.Category category, string spotId, bool isClickable, RandomAdRequestCallback callback = null)
        {
            // request and wait for advertiser id
            RequestAdvertisingIdentifier();
            yield return(new WaitWhile(() => HasAdvertiserId && _advertiserIdSupportEnabled));

            // create new request
            var randomAdRequest = new AdRequest
            {
                ID_GameDev         = developerId,
                str_DevAccessToken = developerAccessToken,
                ID_Game            = developerGameId,
                ID_MediaType       = (int)mediaType,
                ID_Category        = (int)category,
                ID_Spot            = spotId,
                str_Device         = DeviceId,
                dat_Timestamp      = GetTimestampString()
            };

            if (LocationServiceHelper.Instance.LocationReceived)
            {
                randomAdRequest.dec_Latitude  = LocationServiceHelper.Instance.LastLocation.latitude;
                randomAdRequest.dec_Longitude = LocationServiceHelper.Instance.LastLocation.longitude;
            }

            var jsonString = JsonUtility.ToJson(randomAdRequest);

            var pData = System.Text.Encoding.ASCII.GetBytes(jsonString.ToCharArray());

            var request = CreateWebRequest(isClickable ? RequestRandomClickableAdUrl : RequestRandomAdUrl, pData);

            // Wait until the response is returned
            yield return(request.SendWebRequest());

            if (!string.IsNullOrEmpty(request.error))
            {
                if (Debug.isDebugBuild)
                {
                    print("Error response: " + request.error);
                    print("Error Message: " + request.downloadHandler.text);
                }

                var randomVreoResponse = new VreoResponse
                {
                    success = false, result = new Result {
                        ID_MediaType = randomAdRequest.ID_MediaType
                    }
                };

                callback?.Invoke(randomVreoResponse);
            }
            else
            {
                var randomVreoResponse = JsonUtility.FromJson <VreoResponse>(request.downloadHandler.text);
                callback?.Invoke(randomVreoResponse);
            }
        }
Ejemplo n.º 3
0
		IEnumerator RetrieveStreamingAsset(VreoResponse response)
		{
			string mediaUrl;

			if (response.success)
				mediaUrl = response.result.str_MediaURL;
			else
			{
				switch ((MediaType) response.result.ID_MediaType)
				{
					case MediaType.LandscapeVideo:
					case MediaType.PortraitVideo:
						mediaUrl = "vreo_placeholder_video.mp4";
						break;
					default:
						mediaUrl = "vreo_placeholder_image.jpg";
						break;
				}
			}

			var streamingMediaPath = Path.Combine(Application.streamingAssetsPath, mediaUrl);

			WWW wwwReader = new WWW(streamingMediaPath);
			yield return wwwReader;

			if (wwwReader.error != null)
			{
				_loadingState = MediaLoadingState.Failed;
				Debug.LogError("wwwReader error (" + streamingMediaPath + ") : " + wwwReader.error);
			}
			else
			{
				switch ((MediaType) response.result.ID_MediaType)
				{
					case MediaType.MediumRectangle:
					case MediaType.LargeRectangle:
					case MediaType.WideSkyscraper:
					case MediaType.Leaderboard:
						ShowImage(wwwReader);
						break;

					case MediaType.LandscapeVideo:
					case MediaType.PortraitVideo:
						ShowVideo(wwwReader.url);
						break;
				}
			}
		}
Ejemplo n.º 4
0
		// ==============================================================================

		IEnumerator DownloadAdMediaAndLoad(VreoResponse response)
		{
			var type = response.result.ID_MediaType;
			var mediaFormat = response.result.str_MediaTypeName;

			switch ((MediaType) type)
			{
				case MediaType.MediumRectangle:
				case MediaType.LargeRectangle:
				case MediaType.WideSkyscraper:
				case MediaType.Leaderboard:
				{
					WWW wwwReader = new WWW(response.result.str_MediaURL);
					yield return wwwReader;

					if (wwwReader.error != null)
					{
						_loadingState = MediaLoadingState.Failed;
						Debug.LogError("wwwReader error: " + wwwReader.error);
					}
					else
					{
						switch (mediaFormat)
						{
							case "svg":
								ShowSVGImage(wwwReader);
								break;
							default:
								ShowImage(wwwReader);
								break;
						}
					}
					break;
				}
				case MediaType.LandscapeVideo:
				case MediaType.PortraitVideo:
				{
					ShowVideo(response.result.str_MediaURL);
					break;
				}
			}
		}