Search Unity

Playing video from Streaming Assets folder is choppy

Discussion in 'Android' started by EthanHooper1023, Aug 31, 2022.

  1. EthanHooper1023

    EthanHooper1023

    Joined:
    Jan 19, 2017
    Posts:
    24
    I am trying to play a video from the streaming assets folder on android. I can get it to play but it is very choppy
    I am trying to get the video and audio separate so I can swap them out(for multilanguage support) It works well but the video is choppy and the audio becomes desynced from the video.

    Is there a method for preloading the video besided checking if it's prepared?
    I have tried to wait for upwards of 30sec after it's prepared to let it "Load" but still pretty choppy

    Code (CSharp):
    1. public void StartVid()
    2.      {
    3.          string url = "file://" + Application.streamingAssetsPath + "/" + "video.mp4";
    4. #if !UNITY_EDITOR && UNITY_ANDROID
    5.              url = Application.streamingAssetsPath + "/" + "video.mp4";
    6. #endif
    7.          //We want to play from url
    8.          videoPlayer.source = VideoSource.Url;
    9.          videoPlayer.url = url;
    10.          StartCoroutine(prepareVid(Path.Combine(Application.streamingAssetsPath, "audio.wav")));
    11.      }
    12.          private IEnumerator prepareVid(string file)
    13.          {
    14.              videoPlayer.Prepare();
    15.              while (!videoPlayer.isPrepared)
    16.              {
    17.                  Debug.Log("Preparing");
    18.                  yield return null;
    19.              }
    20.    
    21.              UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(file, AudioType.WAV);
    22.              yield return request.SendWebRequest();
    23.    
    24.              audioSource.clip = DownloadHandlerAudioClip.GetContent(request);
    25.    
    26.              Debug.Log("Prepared");
    27.              //yield return new WaitForSeconds(30);
    28.              videoPlayer.Play();
    29.              videoPlayer.started += (trash) => { audioSource.Play(); };
    30.    
    31.              request.Dispose();
    32.          }
    Thank you
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,919
    Last edited: Aug 31, 2022
  3. EthanHooper1023

    EthanHooper1023

    Joined:
    Jan 19, 2017
    Posts:
    24