How to play video from external storage on android 11 (JAVA) programmatically?

Viewed 25

I am working on an app in which I have to get a video from external storage and then I have to play it.

To get Video:

Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
chat.startActivityForResult(Intent.createChooser(intent, "Select Video"), 101);

In onActivityResult method, I am handling it like:

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) 
 {
  super.onActivityResult(requestCode, resultCode, data);
  if (resultCode == RESULT_OK) {
  Uri uri = data.getData();
  filePath = uri.getPath();
  File file;
  file = new File(filePath);
 }

Now I have to play video as:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(uri, "video/*");
startActivity(intent);

I am converting file to base64 for further processing, I am getting bas64 successfully. But I am unable to load video. I want to play this video from Uri/file/base64 on Android 11.

0 Answers
Related