• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by SteenPetersen · Jun 04, 2019 at 04:18 AM · androidvideooculusandroid-manifest

Retrieving and playing a video file stored locally on an android VR headset (Oculus Quest)

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 t$$anonymous$$s is to add the videos to the headset manually and then simply play them from the unity application by fetc$$anonymous$$ng them by code as I will know where they are stored. Alas, I cannot seem to get t$$anonymous$$s to work.

I have attempted to put the videos in the streaming assets folder but unity cannot even build when trying t$$anonymous$$s 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.

 <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" />


I am wondering if there is anyone that has experience with t$$anonymous$$s sort of t$$anonymous$$ng 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.

thanks kindly.
Unity 2019.2 0b1

Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rlogan · Dec 20, 2019 at 04:51 PM 0
Share

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.

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SteenPetersen · Jun 06, 2019 at 03:57 PM

Fixed t$$anonymous$$s like so:

             _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);
             }
 
             if (File.Exists(path))
                 _debugText.text += "\nFile has been found!\n\n";
 
             _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 t$$anonymous$$s message
         _vp.errorReceived -= VideoPlayer_errorReceived;
     }
 
Comment
Bettaxis

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aidenkoh801 · Sep 14, 2019 at 09:59 AM 0
Share

Hi! I've been facing the same issue as you, and my Quest is able to find the correct video file with the android rootpath. However the native video player (exoplayer) is unable to play the video for some reason, I'll like to know if you were able to successfully play your video:)

Here's how my code looks like

         string rootPath = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android", StringComparison.Ordinal));
         string path = Path.Combine(Path.Combine(rootPath, "Android/Data/_Videos"), fileName);
         if (File.Exists(path))
         {
             Debug.Log("path found");
         }
         else
         {
             Debug.Log("path not found");
         }
         
         Play(path);
 
         
     }
 
     public void Play(string moviePath)
     {
         if (moviePath != string.Empty)
         {
             Debug.Log("Playing Video: " + moviePath);
             if (overlay.isExternalSurface)
             {
                 OVROverlay.ExternalSurfaceObjectCreated surfaceCreatedCallback = () =>
                 {
                     Debug.Log("Playing ExoPlayer with SurfaceObject");
                     
                     NativeVideoPlayer.PlayVideo(moviePath, overlay.externalSurfaceObject);
                 };
 
                 if (overlay.externalSurfaceObject == IntPtr.Zero)
                 {
                     overlay.externalSurfaceObjectCreated = surfaceCreatedCallback;
                 }
                 else
                 {
                     surfaceCreatedCallback.Invoke();
                 }
             }
             else
             {
                 Debug.Log("Playing Unity VideoPlayer");
                 videoPlayer.url = moviePath;
                 videoPlayer.Prepare();
                 videoPlayer.Play();
             }
 
             Debug.Log("MovieSample Start");
             isPlaying = true;
         }
         else
         {
             cube.SetActive(false);
             Debug.LogError("No media file name provided");
         }
     }

Thank you so much!

avatar image

Answer by Bettaxis · Oct 02, 2019 at 09:02 PM

@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 t$$anonymous$$s method, I just manually place the video files and link them using the URL, w$$anonymous$$le excluding the videos from the actual Build and Project w$$anonymous$$ch results in a much smaller .apk that is easier to deploy.

I modified your code and used t$$anonymous$$s variation, along with the Android Manifest permission additions.

 VideoPlayer video;        
 private string rootPath;
 private string path;
 private string fileName = "NameOfYourVideo.mp4";  
 
 void Awake()
 {
             video = FindObjectOfType<VideoPlayer>();
             video.errorReceived += VideoPlayer_errorReceived;
 
              if (Application.platform == RuntimePlatform.Android)
              {
                  rootPath = Application.persistentDataPath;
                  path = Path.Combine(rootPath, fileName);
              }
             
             video.url = path;
             video.Play();
 }

T$$anonymous$$s 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 t$$anonymous$$s method you can also update the filename in a script to change/load different videos.

As for your question in https://answers.unity.com/questions/1638368/android-build-videoplayer-cannot-read-mp4-file.html , 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 t$$anonymous$$nk t$$anonymous$$s 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 t$$anonymous$$s time. However, smaller 360 videos do work!

Comment
Wollan

People who like this

1 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bettaxis · Oct 09, 2019 at 04:55 PM 0
Share

So it looks like the file size is another limiting factor for the Quest. I can only play files under 3GB and anything larger does not play.

avatar image Wollan · Oct 20, 2020 at 10:56 AM 0
Share

This worked for me (Unity 2020.1.9f). Only difference is that I didn't manipulate any manifest files directly. Instead I just went into (Unity) Player Settings and changed Write Permission to "External (SDCard") and that proved sufficient. Now playing a 2.8GB 5K stereoscopical .mp4 video on the Quest 2 without problem.

avatar image

Answer by bhupiister · Oct 08, 2020 at 12:33 AM

@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");
         }       
     }
Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

241 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android build - videoplayer - cannot read .mp4 file 1 Answer

Using URL as Source In Video Player on Portable VR 1 Answer

Video system / rendering is stuck on Android OculusGO 0 Answers

Unity on Gear VR with Galaxy S6 2 Answers

Help with error message when uploading to Android Market? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges