My app runs on Android and I am trying to use Video Player component to load videos and play it on an object surface. It works well when I put the videos under path ‘/storage/emulated/0/Android/data/com.xxx.xxx/files’, which is given by Application.persistentDataPath.
However, now I have a need to read video files from Android media shared storage path, like ‘/storage/emulated/0/Movies’. When I try this, the C# script seems unable to find the files. The logs are like this:
AndroidVideoMedia OpenExtractor unable to open /storage/emulated/0/Movies/xxx.mp4, error: 13
AndroidVideoMedia: Error opening extractor: -10004
I have put an AndroidManifest.xml file under Assets/Plugins/Android/ path. The file includes the lines declaring the permission that I think it may need:
But it seems to have no effect.
So how can I reach the videos that are stored under other paths, like Android media shared storage (Movies, Pictures, DCIM, etc.) ? What Android interface does Video Player component call, and does it support reading files from path other than Application.persistentDataPath?
P.S.
My Android version is Android 10, and the app must run on Android 12 as well.
Codes below have been tested:
Directory.Exists('/storage/emulated/0/Movies/') // ---> returns true
File.Exists('/storage/emulated/0/Movies/xxx.mp4') //---> returns false
DirectoryInfo dir = new DirectoryInfo('/storage/emulated/0/Movies/'); FileInfo[] files = dir.GetFiles() // ---> get an exception: *IOException: Permission denied*