提问者:小点点

java.io.FileNotFoundException:没有内容提供者:/storage/emulated/0/test_video.mp4


通常,从图库中选择一个视频并用库剪切,问题是我需要将剪切的视频(它存储在外部存储器:/storage/emulated/0/test_video.mp4中)转换为base64,这就是它失败的地方。我该怎么解决呢?我已经将权限放在清单上,并以编程方式请求这些权限。

//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();
        }

而我在logcast中得到的只有:


共1个答案

匿名用户

我在github的一个帖子上找到了解决方案!只需要包括这一点:

//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