Search Unity

Video VideoPlayer.Prepare() never finishes preparing on Android(works in Editor)

Discussion in 'Audio & Video' started by SirLaur, Dec 21, 2017.

  1. SirLaur

    SirLaur

    Joined:
    Jan 24, 2014
    Posts:
    22
    Hello so I have this problem : I download an AssetBundle from my site which contains an mp4 video. I then load it into a VideoPlayer and prepare and the play it. It works fine in Editor, but the problem is it freezes on Android. So I have this script in my menu which loads the video and enables the Play button when video is ready. When the user presses the buton, another scene is loaded with a script which gets the VideoPlayer component on this gameobject and plays the video ( the line of code I use in this Start is : GameObject.Find("Player").GetComponent<VideoPlayer>().Play() ). This is my main code :

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Video;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;

    public class LoadObjectFromBundle : MonoBehaviour
    {
    public VideoClip VideoClip360;

    public VideoPlayer myVideoPlayer;

    private AssetBundle bundle1;

    private Text downloadStatusText;

    public bool canPlay;

    IEnumerator Start ()
    {
    DontDestroyOnLoad(this.gameObject);

    downloadStatusText = GameObject.Find("DownloadText").GetComponent<Text>();
    downloadStatusText.text = "Downloading and preparing video..";

    Caching.ClearCache();
    yield return new WaitForSeconds(3f);

    StartCoroutine(DownloadObject());
    }

    public IEnumerator DownloadObject()
    {
    WWW www;

    using (www = WWW.LoadFromCacheOrDownload("mySite", 1))
    {
    yield return www;;
    if (www.error != null)
    {
    downloadStatusText.text = "WWW download had an error:" + www.error;
    }
    bundle1 = www.assetBundle;
    }

    AssetBundleRequest request = bundle1.LoadAssetAsync<VideoClip>("myVideo.mp4");
    yield return request;

    VideoClip VideoClip360 = request.asset as VideoClip;

    VideoClip360 = Instantiate(VideoClip360) as VideoClip;

    myVideoPlayer = GameObject.Find("Player").GetComponent<VideoPlayer>();
    myVideoPlayer.clip = VideoClip360;
    myVideoPlayer.Prepare();

    while (!myVideoPlayer.isPrepared)
    {
    downloadStatusText.text = "merge7"; //here it stops
    yield return new WaitForSeconds(0.5f);
    }

    /* while (!myVideoPlayer.isPrepared)
    {
    yield return new WaitForSeconds(5f);
    canPlay = true;
    break;
    }*/ //this while is used to prepare the video for 5 seconds and then load the scene with the video

    if (myVideoPlayer.isPrepared)
    {
    Debug.Log("Ready to go");
    downloadStatusText.text = "Video ready";
    }
    }
    }

    The problem is : with the first while Unity never exists the loop on Android Phone, in the Editor it works fine. If I decomment the second while it loads the scene, but it doesn't play the video, it shows only a black screen(this one also works in Editor). Does anyone have any idea on how to fix this ?
     
    lu526284266 and fiachradunn like this.
  2. gmaziashvili

    gmaziashvili

    Joined:
    Apr 24, 2018
    Posts:
    2
    Have you solved this problem?
     
    fiachradunn likes this.
  3. mloszek

    mloszek

    Joined:
    Jul 22, 2017
    Posts:
    3
    Hi, I have the same issue with preparing video. One note to your code though: you can subscribe to prepareCompleted event rather than checking isPrepared flag in a loop. You can do it like so:

    Code (CSharp):
    1. myVideoPlayer.prepareCompleted -= OnPrepared
    2. myVideoPlayer.prepareCompleted += OnPrepared
    3.  
    4. void OnPrepared(VideoPlayer vp)
    5. {
    6.       //Your code here
    7. }
    However, using this code still doesn't solve "infinite preparing" in my case.
     
  4. Sohaib_techverx

    Sohaib_techverx

    Joined:
    Aug 15, 2019
    Posts:
    16
    I have the same issue. What did you do about the infinite preparing?
     
  5. AhmadouDiarra

    AhmadouDiarra

    Joined:
    Apr 21, 2017
    Posts:
    2
    Any Answer here for this bug ?
     
  6. unity_WHU2VAI6_H7PFg

    unity_WHU2VAI6_H7PFg

    Joined:
    Nov 19, 2019
    Posts:
    14
    I am also having this bug.
     
  7. Deleted User

    Deleted User

    Guest

    I reported that, cause it clearly says in the docs it does not matter if you use file:// or not, but it only works WITHOUT it
    case 14787
     
    The_Island likes this.
  8. juul

    juul

    Joined:
    Jul 31, 2013
    Posts:
    4
    I'm encountering this issue where the video player never invokes the prepareCompleted event in an Android build. It does work on iOS, in the editor, and in an Android development build, but not in the production build on Android. Where do we start with this? Is `VideoPlayer` broken on Android?

    I'm trying to play a clip that's included as an asset in the build, so no URL being used.
     
  9. JackAt360XR

    JackAt360XR

    Joined:
    Apr 16, 2021
    Posts:
    26
    COould it be that is is already prepared before you attach the handler
     
  10. seccia

    seccia

    Joined:
    Nov 11, 2015
    Posts:
    4
    while ( myVideoPlayer.texture==null )