I let the user select a video from the gallery then I save the uri of the video for future use. But after I close the app and reopen it, the video can't play anymore This is intent i use for select video from gallery
private void pickVideoFromGallery() {
Intent opengalleryIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
opengalleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
opengalleryIntent.setType("video/*");
opengalleryIntent.setFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(opengalleryIntent, RESULT_LOAD_VIDEO);
}
I save the video uri as a string
String videoPath = data.getData().toString();
Use:
String videoPath= getIntent().getStringExtra("videoPath"); //From PendingIntent in ForegroundService
viFriendCall.setVideoURI(Uri.parse(videoPath));
viFriendCall.setOnPreparedListener(mp -> mp.setLooping(true));
viFriendCall.start();
And this is the error message i get
E/MediaPlayerNative: Unable to create media player
W/VideoView: Unable to open content: content://com.android.providers.media.documents/document/video%3A9922
java.io.IOException: setDataSource failed.: status=0x80000000
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1209)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1196)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1107)