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

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().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();
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("myVideo.mp4");
yield return request;

VideoClip VideoClip360 = request.asset as VideoClip;

VideoClip360 = Instantiate(VideoClip360) as VideoClip;

myVideoPlayer = GameObject.Find("Player").GetComponent();
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 ?

2 Likes

Have you solved this problem?

1 Like

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:

myVideoPlayer.prepareCompleted -= OnPrepared
myVideoPlayer.prepareCompleted += OnPrepared

void OnPrepared(VideoPlayer vp)
{
      //Your code here
}

However, using this code still doesn't solve "infinite preparing" in my case.

I have the same issue. What did you do about the infinite preparing?

Any Answer here for this bug ?

I am also having this bug.

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

1 Like

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.

COould it be that is is already prepared before you attach the handler

while ( myVideoPlayer.texture==null )