private IEnumerator PlayNextVideoCoRoutine() { MediaPlayerCtrl.Stop(); MarkCurrentVideoAsWatched(); var backupOrientation = Screen.orientation;
// Reverts to AutoRotation (workaround for AdMob)
// Please note that at this moment the app has probably locked the orientation to Landscape for gameplay purposes Screen.orientation = ScreenOrientation.AutoRotation; while(Screen.orientation != ScreenOrientation.AutoRotation) yield return null; yield return null;
yield return AdsController.Instance.TryPlayVideoAdCoRoutine();
yield return null; yield return null;
Screen.orientation = backupOrientation;
while(Screen.orientation != backupOrientation) yield return null; yield return null; StartPlayRandomVideoCoroutine(_playingMultipleVideos); _controlsPlaybackGroup.PerformTransitionControlsGroup(VideoPlayerControlState.Inactive); }
public IEnumerator TryPlayVideoAdCoRoutine() { if (!CanShowAds) yield break;
Debug.LogFormat("TRYING TO PLAY VIDEO AD - {0}", GameController.Instance.UserData.MustShowVideoAdToUserAsap); if (!GameController.Instance.UserData.MustShowVideoAdToUserAsap) yield break;
Debug.Log("PLAYING VIDEO AD"); Future<bool> adResultFuture = new Future<bool>(); PlayVideoAd(adResultFuture);
while (!adResultFuture.IsFinished) yield return null;
if (adResultFuture.Value) SaveVideosWatchedUserData();
Debug.Log("FINISHED PLAYING VIDEO AD"); yield return null; }
private void PlayVideoAd(Future<bool> adResultFuture) { if (Application.isEditor) { Debug.LogWarning("PLAYING MOCK VIDEO AD!!!"); EvtVideoAdPlayed?.Invoke(); adResultFuture.Value = true; return; }
TryInit();
if (_adResultFuture != null) Debug.LogWarning("[AdController] Trying to play video ad but there is already an Ad Result Future defined!");
_adResultFuture = adResultFuture;
if (!_interstitialAd.IsLoaded()) { Debug.Log("[AdController] Video Not Available"); adResultFuture.Value = false; return; }
Debug.LogFormat("[AdController] Playing Video Ad"); _interstitialAd.OnAdClosed += (sender, args) => { Debug.LogFormat("[AdController] Ad Finished Playing"); adResultFuture.Value = true; }; _interstitialAd.Show(); }--
---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/5998d37d-45a0-4159-9acf-57fe82c2b19f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public IEnumerator TryPlayVideoAdCoRoutine() { if (!CanShowAds) yield break;
#if UNITY_EDITOR || DEVELOPMENT_BUILD Debug.LogFormat("[AdsController] TRYING TO PLAY VIDEO AD - {0}", GameController.Instance.UserData.MustShowVideoAdToUserAsap);#endif if (!GameController.Instance.UserData.MustShowVideoAdToUserAsap) yield break;
#if UNITY_EDITOR || DEVELOPMENT_BUILD Debug.LogFormat("[AdsController] Changing Screen Orientation to {0}", ScreenOrientation.AutoRotation);#endif var backupOrientation = Screen.orientation; Screen.orientation = ScreenOrientation.AutoRotation; yield return null;
const float orientationChangeTimeout = 1f;
float nextTimeout = Time.unscaledTime + orientationChangeTimeout; while(Screen.orientation != ScreenOrientation.AutoRotation && Time.unscaledTime < nextTimeout) yield return null; #if UNITY_EDITOR || DEVELOPMENT_BUILD Debug.LogFormat("[AdsController] Screen Orientation Changed to {0}", Screen.orientation);#endif Debug.Log("[AdsController] PLAYING VIDEO AD"); Future<bool> adResultFuture = new Future<bool>(); PlayVideoAd(adResultFuture);
while (!adResultFuture.IsFinished) yield return null; Screen.orientation = backupOrientation; yield return null; nextTimeout = Time.unscaledTime + orientationChangeTimeout; while(Screen.orientation != backupOrientation && Time.unscaledTime < nextTimeout) yield return null; #if UNITY_EDITOR || DEVELOPMENT_BUILD Debug.LogFormat("[AdsController] Screen Orientation Changed BACK to {0}", Screen.orientation);#endif if (adResultFuture.Value) SaveVideosWatchedUserData();
Debug.Log("[AdsController] FINISHED PLAYING VIDEO AD"); yield return null; }yield return null;Screen.orientation = backupOrientation;
while(Screen.orientation != backupOrientation) yield return null;yield return null;StartPlayRandomVideoCoroutine(_playingMultipleVideos);_controlsPlaybackGroup.PerformTransitionControlsGroup(VideoPlayerControlState.Inactive);
}
public IEnumerator TryPlayVideoAdCoRoutine(){if (!CanShowAds) yield break;
Debug.LogFormat("TRYING TO PLAY VIDEO AD - {0}", GameController.Instance.UserData.MustShowVideoAdToUserAsap);if (!GameController.Instance.UserData.MustShowVideoAdToUserAsap) yield break;
Debug.Log("PLAYING VIDEO AD");
Future<bool> adResultFuture = new Future<bool>();PlayVideoAd(adResultFuture);while (!adResultFuture.IsFinished) yield return null;
if (adResultFuture.Value) SaveVideosWatchedUserData();Debug.Log("FINISHED PLAYING VIDEO AD");yield return null;}
private void PlayVideoAd(Future<bool> adResultFuture){if (Application.isEditor){Debug.LogWarning("PLAYING MOCK VIDEO AD!!!");EvtVideoAdPlayed?.Invoke();adResultFuture.Value = true;return;}TryInit();if (_adResultFuture != null) Debug.LogWarning("[AdController] Trying to play video ad but there is already an Ad Result Future defined!");_adResultFuture = adResultFuture;if (!_interstitialAd.IsLoaded()){Debug.Log("[AdController] Video Not Available");adResultFuture.Value = false;return;}Debug.LogFormat("[AdController] Playing Video Ad");_interstitialAd.OnAdClosed += (sender, args) =>{Debug.LogFormat("[AdController] Ad Finished Playing");adResultFuture.Value = true;};_interstitialAd.Show();}
--
---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/5998d37d-45a0-4159-9acf-57fe82c2b19f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/b62b5847-0285-4b81-9008-0a1764942b9b%40googlegroups.com.