Android Unity3D VideoPlayer 播放"来自 URL"的视频无法正常工作



平台:Unity 2020.1.0f1

我在创建一个小游戏时遇到了一个奇怪的问题,该游戏旨在将视频从远程URL下载到Application.PersistentDataPath;RenderTexture"-通过按下特定视频的按钮。

在编辑器中,一切都很好。。。

在IOS上,一切都很好。。。

在Android上(无论哪个版本(,只有资产文件夹中的视频才能正常播放。从Application.persistentDataPath访问下载的文件在Android上什么都不显示。。。

我检查的东西(除了简单的失明(:

  • "外部写入权限">强迫一切开启";内部";。。。不工作
  • 使用Path.Combine((和/或";字符串文件路径=">
  • "不同的视频格式">不。。。资产视频在没有转码的情况下正常播放(它是h.264 AVC,650x650px,30fps-AAC音频,44.1kHz,Bps 32(

下面的示例代码,测试场景也可以在这里下载:http://weristaxel.de/upload/Videotest.unityhttp://weristaxel.de/upload/VideotestController.cs

Unity资产文件夹中的视频:https://corolympics.azurewebsites.net/assets/game1howto.mov

我错过了什么?

public void PlayFromPersistent()
{
// NOT WORKING ON ANDROID
VideoPlayer VideoHowTo = VideotestCanvas.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
string filePath = Application.persistentDataPath + "/game2howto.mov";
VideoHowTo.Stop();
VideoHowTo.url = filePath;
VideoHowTo.source = VideoSource.Url;
DebugText.text = "VideoHowTo.url = " + filePath;
VideoHowTo.Prepare();
VideoHowTo.Play();
}
public void PlayFromAssets()
{
// WORKING ON ANDROID
VideoPlayer VideoHowTo = VideotestCanvas.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
VideoHowTo.Stop();
VideoHowTo.clip = assetVideo;
VideoHowTo.source = VideoSource.VideoClip;
DebugText.text = "VideoHowTo.clip set -  original path " + assetVideo.originalPath;
VideoHowTo.Play();
}
public void DownloadVideo()
{
// THIS DOWNLOADS A TEST VIDEO TO "persistentDataPath"...
string url = "https://corolympics.azurewebsites.net/assets/game2howto.mov";
Debug.Log("Downloading " + url);
var uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
string filename = url.Split('/').Last();
string path = Path.Combine(Application.persistentDataPath , filename);
uwr.downloadHandler = new DownloadHandlerFile(path);
uwr.SendWebRequest();
DebugText.text = "Download to " + path + " finished";
}
public void AddListener()
{
// NOT WORKING ON ANDROID - THIS ADDS A LISTENER TO AN EMPTY BUTTON TO EMULATE THE TARGET BEHAVIOUR
Button button = VideotestCanvas.transform.Find("FromPersistentListenerButton").GetComponent<Button>();
Color blueColor = new Color32(52, 152, 219, 255);
button.GetComponent<Image>().color = blueColor;
button.onClick.AddListener(() =>
{
VideoPlayer VideoHowTo = VideotestCanvas.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
string filePath = Application.persistentDataPath + "/game2howto.mov";
VideoHowTo.Stop();
VideoHowTo.url = filePath;
VideoHowTo.source = VideoSource.Url;
DebugText.text = "VideoHowTo.url = " + filePath;
VideoHowTo.Play();
});
}

如果您仍然停滞不前,我会尝试在添加侦听器事件时创建一个独立函数。因此它将类似于'button.onClick.AddListener(((=>IndFunction(((',而不是每次都创建一个新实例。不久前,我遇到了类似的问题,我为每个按钮创建了一个可编辑的脚本来存储每个按钮的信息,并根据图像链接和图像名称列表设置每个按钮。

最新更新