Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Video Android application crash when playing 4 videos together

Discussion in 'Audio & Video' started by Eco-Editor, Dec 7, 2018.

  1. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Hi all!

    I've been searching the web for the past month for a solution of my 4 videos not playing together on OculusGo.

    When I've placed the videos in a clear scene they played, when placed in the original scene the app crahses.

    In the original scene, I have 1 image 360 degrees as the whole scene (cubemap), Audio for 4 characters.
    in total I have 5 videos but only 4 play together.

    the first script is to load resource:

    Code (CSharp):
    1. public string charName;
    2.     private bool isLoaded = false;
    3.     private VideoClip m_videoAsset;
    4.     private string kRESOURCE_PATH;
    5.     private VideoPlayer player;
    6.  
    7.  
    8.     private void Awake()
    9.     {
    10.         kRESOURCE_PATH = "Videos/" + charName;
    11.         player = GetComponent<VideoPlayer>();
    12.  
    13.  
    14.     }
    15.     private void Update()
    16.     {
    17.         if (m_videoAsset == null && !isLoaded)
    18.         {
    19.             DoLoadAsset();
    20.             isLoaded = true;
    21.         }
    22.     }
    23.  
    24.     private void DoLoadAsset()
    25.     {
    26.         m_videoAsset = Resources.Load<VideoClip>(kRESOURCE_PATH);
    27.         print("loaded resource is: " + m_videoAsset.name);
    28.         player.clip = m_videoAsset;
    29.         StartCoroutine(Unloading());
    30.      
    31.     }
    32.  
    33.     IEnumerator Unloading()
    34.     {
    35.         double clipLenght = player.clip.length;
    36.         yield return new WaitForSeconds((float)clipLenght);
    37.         if (player.isLooping) //this is for debugging and will not go into the final build - no clip is looping
    38.         {
    39.            yield return null;
    40.         }
    41.         else
    42.         {
    43.  
    44.             DoUnloadAsset();
    45.         }
    46.      
    47.     }
    48.  
    49.     private void DoUnloadAsset()
    50.     {
    51.  
    52.         Resources.UnloadAsset(m_videoAsset);
    53.         Debug.Log("asset is down");
    54.         m_videoAsset = null;
    55.  
    56.     }

    the second script is to play video clip when audio source begins:

    Code (CSharp):
    1.     public float waiting;
    2.     public AudioSource characterAudio;
    3.  
    4.     VideoPlayer videoPlayer;
    5.     bool videoStarted = true;
    6.    
    7.  
    8.     // Use this for initialization
    9.     void Awake () {
    10.        
    11.         videoPlayer = GetComponent<VideoPlayer>();
    12.        
    13.        
    14.     }
    15.  
    16.     private void Update()
    17.     {
    18.         if (characterAudio != null)
    19.         {
    20.             if (characterAudio.isPlaying && videoStarted)
    21.             {
    22.                 StartCoroutine(StartVideo());
    23.                 videoStarted = false;
    24.                 Debug.Log(characterAudio.name + " called once from update");
    25.             }
    26.         }
    27.     }
    28.  
    29.     IEnumerator StartVideo()
    30.     {
    31.         yield return new WaitForSeconds(waiting);
    32.         videoPlayer.enabled = true;
    33.         videoPlayer.Prepare();
    34.         while(!videoPlayer.isPrepared)
    35.         {
    36.             Debug.Log("video is preparing " + characterAudio.name);
    37.             yield return null;
    38.         }
    39.  
    40.         videoPlayer.Play();
    41.         Debug.Log("videoStarted, char name is: " + characterAudio.name);
    42.     }
    why my app is crashing?