我的应用可以从Firebase下载视频内容,将其保存到Application.dataPath,然后在编辑器中播放。但是,当我将其构建到iOS时,它找不到该文件。我也尝试过使用应用程序。持久数据,但它似乎确实存在。 有什么有用的指示吗?
原谅我丑陋的代码:/______ ____ 我已经删除了蹩脚的评论等,整理了一下,但我认为这让我了解了我正在使用的技巧......
public void FUKN_download_viddy()
{
FirebaseStorage storage = FirebaseStorage.DefaultInstance;
StorageReference path_reference = storage.GetReference("videoname.mp4");
pathToSaveTo = "file://" +
Application.dataPath +
"/Resources/Adam/Year 1 Semester 1/"+
"videoname.mp4";
path_reference.GetFileAsync(pathToSaveTo).ContinueWith(task => {
if (!task.IsFaulted && !task.IsCanceled)
{
Debug.Log("File downloaded.");
}
});
}
// ____________
// _________
public void FUKN_play_viddy()
{
string viddyplayerpath = "Adam/Year 1 Semester 1/" + "videofile";
var viddyKlip = Resources.Load<VideoClip>(viddyplayerpath);
VideoPlayer videoPlayer = GetComponent<VideoPlayer>();
videoPlayer.clip = viddyKlip; // index offset
videoPlayer.Play();
}
// _________
我认为您的问题是Resources.Load
拉入Assets/Resources
目录中的元素 - 而不是您的文件系统(请参阅文档页面(。
你想要使用VideoPlayer.src,如此处所述。
前任:
public class TestVideo: MonoBehaviour {
[SerializeField] private VideoPlayer _videoPlayer;
public Play() {
_videoPlayer.src = "file://" + Application.persistentDataPath + "/Resources/Adam/Year 1 Semester 1/" + "videoname.mp4";
_videoPlayer.Play();
}
}
请注意,我使用了 persistentDataPath,dataPath 在 iOS 和 Android 上将是只读的。
我希望这有所帮助!
--帕特里克