I’m building an .apk for the Quest 2 and need to be able to copy two large video files to the persistentDataFolder
. The video files are stored in an OBB file.
I have tried using ‘UnityWebRequest’ but are yet without any luck.
using UnityEngine;
using UnityEngine.Networking;
using System.IO;
public class CopyFilesFromOBB : MonoBehaviour
{
private string[] videoFiles = { "vid1.mkv", "vid2.mkv" };
IEnumerator Start()
{
foreach (string videoFile in videoFiles)
{
string sourcePath = Path.Combine(Application.streamingAssetsPath, videoFile);
string localPath = Path.Combine(Application.persistentDataPath, videoFile);
if (!File.Exists(localPath))
{
if (sourcePath.Contains("://") || sourcePath.Contains(":///"))
{
// Load file from OBB using UnityWebRequest
UnityWebRequest www = UnityWebRequest.Get(sourcePath);
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
{
// Save file to persistent data path
File.WriteAllBytes(localPath, www.downloadHandler.data);
Debug.Log(videoFile + " is copied");
}
else
{
Debug.LogError("Failed to load " + videoFile + " from OBB: " + www.error);
}
}
else
{
Debug.LogError("Invalid OBB file path: " + sourcePath);
}
}
else
{
Debug.Log(videoFile + " already exists in the persistent data path");
}
}
}
}
This produces the following error log:
05-24 17:45:56.175 5788 5812 E Unity : Failed to load vid1mkv from OBB: Cannot connect to destination host
05-24 17:45:56.175 5788 5812 E Unity : d:MoveNext()
05-24 17:45:56.175 5788 5812 E Unity : UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
05-24 17:45:56.175 5788 5812 E Unity :
05-24 17:45:56.177 5788 5812 E Unity : Failed to load vid2.mkv from OBB: Cannot connect to destination host
05-24 17:45:56.177 5788 5812 E Unity : d:MoveNext()
05-24 17:45:56.177 5788 5812 E Unity : UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
Have been struggling with this for a few days now, looking for answers online, tried several different methods, every single one leading to errors or causing the entire build to crash. I’m certain that the path for the OBB file is correct since I’m able to access other assets from it.
Would really appreciate some assistance here - thanks in advance.