我在Unity工作,在项目中有一些大型视频文件。该项目适用于iOS和Android。 Android是主要焦点。我希望能够在首次安装应用程序时将它们移动到PersistentDataPath。现在它们只是在脚本中引用,我使用AVPro来播放它们,所以它们不会被包含在构建中,除非我将它们放在Resources文件夹或StreamingAssets中并且文件不能从那些文件夹。我是否可以通过某种方式将文件包含在APK中,以便在将这些文件复制到PersistantDataPath后将其删除?
我有这个脚本用于从StreamingAssets文件夹中将文件复制到PersistantDataPath,但我无法从那里删除。
bool copyLargeVideoToPersistentDataPath(string videoNameWithExtensionName)
{ string path = Path.Combine(Application.streamingAssetsPath,videoNameWithExtensionName);
string persistentPath = Path.Combine(Application.persistentDataPath, "Videos");
persistentPath = Path.Combine(persistentPath, videoNameWithExtensionName);
bool success = true;
try
{
using (FileStream fromFile = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (FileStream toFile = new FileStream(persistentPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
byte[] buffer = new byte[32 * 1024];
int bytesRead;
while ((bytesRead = fromFile.Read(buffer, 0, buffer.Length)) != 0)
{
toFile.Write(buffer, 0, bytesRead);
}
Debug.Log("Done! Saved to Dir: " + persistentPath);
Debug.Log(videoNameWithExtensionName + " Successfully Copied Video to " + persistentPath);
text.text = videoNameWithExtensionName + " Successfully Copied Video to " + persistentPath;
}
}
}
catch (Exception e)
{
Debug.Log(videoNameWithExtensionName + " Failed To Copy Video. Reason: " + e.Message);
text.text = videoNameWithExtensionName + " Failed To Copy Video. Reason: " + e.Message;
success = false;
}
return success;
}