I am in the midst of making some prototypes that require me to play large video files from a unity application (10gb+). These are 360 videos that will be played in a hospital environment and therefore I am hard pressed to simply upload these videos to a server as I am doing now and streaming them. The Hospital does not allow downloads like these and the connection is not good enough to stream it effectively.
My solution to this is to add the videos to the headset manually and then simply play them from the unity application by fetching them by code as I will know where they are stored. Alas, I cannot seem to get this to work.
I have attempted to put the videos in the streaming assets folder but unity cannot even build when trying this as I get java heap space problems I have furthermore added the permissions to the Android manifest so it should have permission to fetch the video.
I am wondering if there is anyone that has experience with this sort of thing that would kindly shed some light on how to go about placing a video file locally in the headset (most likely in the com.< companyname>.< applicationname> folder or “persistent path” ) and then playing it from script or from the videoplayer Url/Path.
_vp.url = path;
_vp.Play();
private void VideoPlayer_errorReceived(VideoPlayer source, string message)
{
/// So that I can see the debug message in the headset in my case
_debugText.text += message;
/// To avoid memory leaks, unsubscribe from the event
/// otherwise it could continuously send this message
_vp.errorReceived -= VideoPlayer_errorReceived;
}
@SteenPetersen your answer really helped me with the project I am working on. In the same vein of large 360 videos that are played through a Unity App for the Quest. I was not able to build .apks with the videos linked natively in the Unity VideoClip component as the .apk would be too huge and would result in Gradle errors, with this method, I just manually place the video files and link them using the URL, while excluding the videos from the actual Build and Project which results in a much smaller .apk that is easier to deploy.
I modified your code and used this variation, along with the Android Manifest permission additions.
This in the URL leads to the path in the Quest at “Internal shared storage\Android\data\com.CompanyName.ProjectName\files” where I placed the large videos I needed and with this method you can also update the filename in a script to change/load different videos.
As for your question in Android build - videoplayer - cannot read .mp4 file - Questions & Answers - Unity Discussions , I encountered that error as well and I was able to resolve it by making sure the target was in the com.CompanyName.ProjectName\Files instead of the Android\Data_Videos that you placed them in. I think this has to do with how Unity accesses files at runtime (see here), putting it in the com. folder makes it work! Note that Above ~3GB videos don’t seem to play on the Quest and I am unsure as to if it’s a Quest limitation due to the 4GB of RAM or a Unity issue at this time. However, smaller 360 videos do work!
I am trying this method and I only get a green screen when I play. It is definitely finding the video. It should not be a codec issue as the same video works if I assign the file directly to the videoplayer in unity instead of loading through URL from storage. Not sure what to try next.
@SteenPetersen
Drag video component from inspector. Please see video on how to how to set raw image and render texture before playing videos on unity, you will find plenty of those
private string rootPath;
public VideoPlayer video; //Drag video component
private string path;
public Button PlayButton; //Drag button from inspector
public InputField fileName; //Drag Input field from inspector
void Awake()
{
video.playOnAwake = false;
}
void Update()
{
if (video.isPlaying)
{
PlayButton.interactable = false;
}
else
{
PlayButton.interactable = true;
}
}
public void PlayVideo() //Function assigned to play button
{
if (fileName.text.Length > 0)
{
Debug.Log("Persistent data path" + Application.persistentDataPath);
rootPath = Application.persistentDataPath;
path = Path.Combine(rootPath, fileName.text + ".mp4");
//}
if (File.Exists(path))
{
video.url = path;
video.Play();
}
else
{
Debug.Log("File not found, please check file name!");
}
}
else
{
Debug.Log("Please enter file name");
}
}