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 ?