• 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 06, 2019 at 12:11 PM · androidvrvideooculusandroid-manifest

Android build - videoplayer - cannot read .mp4 file

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 + "\n";
         _debugText.text += path + "\n";
 
         if (File.Exists(path))
             _debugText.text += "\nFile has been found!\n\n";
 
         _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.

alt text
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.

comsteenthesis-20190606-140017.jpg (32.3 kB)
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Bettaxis · Oct 02, 2019 at 09:06 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 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. VideoPlayer video;
private string rootPath; private string path; private string fileName = "NameOfYourVideo.mp4";

void Awake() { video = FindObjectOfType(); video.errorReceived += VideoPlayer_errorReceived;

           if (Application.platform == RuntimePlatform.Android)
           {
               rootPath = Application.persistentDataPath;
               path = Path.Combine(rootPath, fileName);
           }
          
          video.url = path;
          video.Play();

}

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 issue with playing the video, 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 and it plays flawlessly! 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!

Comment
micfogas
memelotsqui

People who like this

2 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 micfogas · Nov 30, 2020 at 03:08 PM 0
Share

This is old but just came across it. So far as I know, the limit exists only with 32-bit builds. This is due to memory and file size limitations of 32-bit architecture. Using 64-bit builds should not have a problem with file sizes >4gb.

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

264 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 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

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

Video system / rendering is stuck on Android OculusGO 0 Answers

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

Video textures appearing white in Samsung Gear Vr Android unity 0 Answers

How to suppress system bars on Android? 2 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