I am placing a video on my oculus quest headset and accessing it from the unity build. The idea was then to load the video into the video player and play it so that I could avoid having to download the file or build a unity project with a 8gb+ 360 video file.
This is the code that fetches the video on the headset.
string rootPath;
string path;
[SerializeField] string fileName;
[SerializeField] VideoPlayer _vp;
[SerializeField] TextMeshProUGUI _debugText;
bool readyToPlay = true;
void Start()
{
_vp = GetComponent<VideoPlayer>();
_vp.errorReceived += VideoPlayer_errorReceived;
if (Application.platform == RuntimePlatform.Android)
{
rootPath = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android", StringComparison.Ordinal));
path = Path.Combine(Path.Combine(rootPath, "Android/Data/_Videos"), fileName);
}
_debugText.text += rootPath + "
";
_debugText.text += path + "
";
if (File.Exists(path))
_debugText.text += "
File has been found!
";
_vp.url = path;
if (readyToPlay)
{
_vp.Play();
}
}
private void VideoPlayer_errorReceived(VideoPlayer source, string message)
{
#if UNITY_EDITOR
Debug.Log(message);
#endif
readyToPlay = false;
_debugText.text += message;
/// To avoid memory leaks, unsubscribe from the event
/// otherwise it could continuously send this message
_vp.errorReceived -= VideoPlayer_errorReceived;
}
private void OnDisable()
{
_vp.errorReceived -= VideoPlayer_errorReceived;
}
}
It is finding the file but it is saying “cannot read file” as can be seen by this screenshot.
I have also made sure that the android.Manifest has the correct permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Im simply wondering why not when I can play this file in the editor no problem. Any input would be greatly appreciated.