Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Issues with Ads - Video player error (video_player_prepare_timeout)

Discussion in 'Unity Ads & User Acquisition' started by unitynoob24, Jul 4, 2023.

  1. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    Not sure if this is a bug or something is up with my logic.

    I integrated Unity ads into my upcoming mobile game a few months ago, and did the basic textbook stuff that is readily available via tutorials / the Unity documentation. My game has been in QA for the last few weeks now, and I have been having a lot of issues around Ads, specifically on Android. So today I spun up a totally blank project with a fresh ad implementation and I'm seeing some different behavior.

    We found that sliding the app out of focus actually returns Skipped (if the ad doesn't totally die) which was problematic for a while not knowing this, as my reward ad implementation never was checking for Skipped in the OnUnityAdsShowComplete callback since the ad unit is set to unskippable.

    I also observed that on three of my friends Pixels running android 13 and 14(beta) interacting with an ad at all, will either throw and error or just they return to the app and it counts it as skipping the ad, even after returning to app and letting the ad finish playing. Sometimes it results in just a black screen when the ad starts again and they are stuck forever.

    On Android 12 with my Galaxy S10 though I am able to interact with the ads and return to the app and it finishes the ad successfully.

    Anyways, so my newest issue that I am now seeing is bricking the entire app. Like I said, I created a totally fresh project just so I could isolate the ad stuff entirely. I'm using Unity 2020.3.45 and Advertisement Legacy 4.4.2 - the app is super straight forward, I have a button for each ad unit id and then a ui element that receives my debug.logs. Basically I can start a reward ad video, send app to background, bring back into focus and it will either work fine (triggering my exploit event - since I'm skipping an unskippable ad) OR it will throw a video player error (video_player_prepare_timeout) Shortly after seeing that appear, without doing anything the app just 100% shuts off. I have seen errors logged when spam testing my actual game, but none of them shut my app off, so this is a new one.

    Here is my Reward Ad implementation. It is kicked off from my AdManager once the Advertisement object hits its OnInitializationComplete callback. Then pressing the Reward button in this test app calls the ShowAd() method here.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Advertisements;
    4. using UnityEngine.Events;
    5.  
    6. public class RewardAd : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener{
    7.  
    8.     public UnityEvent OnAdLoaded = new UnityEvent();
    9.     public UnityEvent OnSuccess = new UnityEvent();
    10.     public UnityEvent<string> OnFailure = new UnityEvent<string>();
    11.     public UnityEvent OnExploit = new UnityEvent();
    12.     public UnityEvent OnResolved = new UnityEvent();
    13.  
    14.         private string adUnitId;
    15.         private bool isAdLoaded;
    16.  
    17.     public void Initialize(){
    18.         adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer) ?
    19.             AdManager.AdUnit.Rewarded_iOS.ToString() : AdManager.AdUnit.Rewarded_Android.ToString();
    20.  
    21.         // Debug Logs
    22.         OnAdLoaded.AddListener(() => Debug.Log("Reward Ad has loaded, ready to play."));
    23.         OnSuccess.AddListener(() => Debug.Log("Reward Ad was viewed successfully."));
    24.         OnFailure.AddListener(error => Debug.Log("Reward Ad failure: " + error));
    25.         OnExploit.AddListener(() => Debug.Log("Reward Ad was skipped. Exploit!"));
    26.  
    27.         OnResolved.AddListener(() => ResolveAd());
    28.         LoadAd();
    29.     }
    30.  
    31.     private void LoadAd() => Advertisement.Load(adUnitId, this);
    32.     public void OnUnityAdsAdLoaded(string adUnitId){
    33.         isAdLoaded = true;
    34.         OnAdLoaded.Invoke();
    35.     }
    36.  
    37.     public void ShowAd(){
    38.        
    39.         if (!isAdLoaded){
    40.             OnAdLoaded.AddListener(ShowAd);
    41.             LoadAd();
    42.         }
    43.         else{
    44.             Advertisement.Show(adUnitId, this);
    45.         }
    46.     }
    47.  
    48.     private void ResolveAd(){
    49.         OnAdLoaded.RemoveListener(ShowAd);
    50.         isAdLoaded = false;
    51.         LoadAd();
    52.     }
    53.  
    54.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState){
    55.  
    56.         if (showCompletionState == UnityAdsShowCompletionState.COMPLETED)
    57.             OnSuccess.Invoke();
    58.  
    59.         if (showCompletionState == UnityAdsShowCompletionState.SKIPPED ||
    60.             showCompletionState == UnityAdsShowCompletionState.UNKNOWN)
    61.             OnExploit.Invoke();
    62.  
    63.         OnResolved.Invoke();
    64.     }
    65.  
    66.     public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message){
    67.         OnFailure.Invoke(message.ToString());
    68.         OnResolved.Invoke();
    69.     }
    70.     public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message){
    71.         OnFailure.Invoke(message.ToString());
    72.         OnResolved.Invoke();
    73.     }
    74.     public void OnUnityAdsShowStart(string adUnitId) {}
    75.     public void OnUnityAdsShowClick(string adUnitId) {}
    76. }
    77.  
    Attached is a screen shot of the console log right before it crashes.

    Thanks if you made it this far! Just curious if I'm not setting this up correctly, or if this is intended behavior since I am slamming it with video requests (if so what would be best practices to prevent these crashes) or if there are issues with my logic, etc etc. Open to any and all feedback :)
     

    Attached Files: