0

Generally a video is chosen from the gallery and cut with a library, the problem is that I need to convert that cut video (that it is stored in the external memory: /storage/emulated/0/test_video.mp4) to base64 and that's where it fails. How can I solve it? I already put the permissions on the manifest and request for them programmatically.

//Getting video from previous activity
        Uri selectedVideo = Uri.parse(intent.getStringExtra("trimmedVideo"));
        Log.d(Global.getTag(), "path: "+selectedVideo.toString());

 //Converting Selected video to base64
        try {
            InputStream in = getContentResolver().openInputStream(selectedVideo);  <---This line fails
            byte[] bytes = Global.getBytes(in);
            Log.d(Global.getTag(), "bytes size= "+bytes.length);
            video_base64 = Base64.encodeToString(bytes,Base64.DEFAULT);
            Log.d(Global.getTag(), "Base64string= "+ video_base64);
        } catch (Exception e) {
            e.printStackTrace();
        }

And all I get in logcast is:

enter image description here

Ela96
  • 35
  • 6

1 Answers1

0

I found the solution on a github post! Just need to include this:

//Getting video from previous activity
Uri selectedVideo = Uri.parse(intent.getStringExtra("trimmedVideo"));

Uri selectedVideoFinal = null;
        if (selectedVideo.getScheme() == null){
            selectedVideoFinal = Uri.fromFile(new File(selectedVideo.getPath()));
        }else{
            selectedVideoFinal = selectedVideo;
        }


 Log.d(Global.getTag(), "path: "+selectedVideoFinal);

 MediaMetadataRetriever mMMR = new MediaMetadataRetriever(); ...continue code
Ela96
  • 35
  • 6