harmonwood / capacitor-video-player

Capacitor Video Player Plugin
MIT License
116 stars 46 forks source link

URL format required for internal files reading (App crash or file not found) #139

Closed etiennebon closed 12 months ago

etiennebon commented 12 months ago

Hello,

On Android, I can successfully record videos in my App folder (file:///data/user/0/MY_APP_NAME/files/xxxx.mp4) or in the "Documents" folder. But when I use these path to run initPlayer it, I get either a "initPlayer command failed: Video file not found" or the Application crashed suddenly without any notification.

I tried the following, but nothing works:

file:///data/user/0/MY_APP_NAME/files/xxxx.mp4 => That makes the Application crash immediatly. Directory.Data + xxxx.mp4 => Resulting in "data/xxxx.mp4" => File Not Found. 'application/files/' + xxxx.mp4 => That makes the Application crash immediatly. I tried to generate a base64 file and play directly, but there, I also get a "File not found": "data:video/mp4;base64,${file.data}"

     The script used to generate the base64 URL:

########################## async getVideoUrl(fullPath) {

//const path = 'vidz/' + fullPath.substr(fullPath.lastIndexOf('/') + 1);
const path = fullPath.substr(fullPath.lastIndexOf('/') + 1);
console.log("Le FULL PATH");
console.log(path);
const file = await Filesystem.readFile({
    path: path,   // 123123.mp4
    directory: Directory.Data  // DATA/
  });
return `data:video/mp4;base64,${file.data}`;

} #########################

My question: If I am able to record and store a video locally on my android phone, what is the URL that I need to use for playing it, please?

I went through API documentation, but I don't understand how to use that information: _From Application Folder iOS Plugin . application/files/video.mp4 is corresponding to : /data/Containers/Data/Applications/YOUR_APPLICATION/Documents/files/video.mp4 Android Plugin . application/files/video.mp4 is corresponding to : /data/user/0/YOUR_APPLICATIONPACKAGE/files/video.mp4

Thank you for your support. E.

etiennebon commented 12 months ago

Hello,

I finally solved my issue by following advice provided in #109 and adding the following in my manifest.xml file: <meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:value="com.google.android.exoplayer2.ext.cast.DefaultCastOptionsProvider"> In term of URL, I am using: 'application/files/' + videoName.mp4

Regards, E.