java.io.filenotfoundexception:无内容提供商:/storage/emulated/0/test\u video.mp4

g6baxovj  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(319)

通常从库中选择一个视频并用库进行剪切,问题是我需要将剪切的视频(它存储在外部存储器:/storage/emulated/0/test\u 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里得到的只是:

z9ju0rcb

z9ju0rcb1#

我在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

相关问题