android – 使用新的存储访问框架(SAF)将视频录制到外部SD卡时出现IllegalStateException

我有以下方法,它适用于Android 4.3或更早版本的内部存储和外部SD卡:

    public void Recorder_Prepare() {        
        recorder = new MediaRecorder();
        recorder.setPreviewdisplay(holder.getSurface());
        mCamera.unlock();
        recorder.setCamera(mCamera);
        recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        recorder.setProfile(camcorderProfile);
        recorder.setVideoSize(ResolutionWidth, ResolutionHeight);

        File DirectoryExistCheck = new File(VideoFolderAbsolutePATH);
        if(!DirectoryExistCheck.exists()) {
            DirectoryExistCheck.mkdir();
        }

        String VideoPath = VideoFolderAbsolutePATH + separator + "Video.mp4"; 
        File NewVideoFile = new File(VideoPath);
        recorder.setoutputFile(NewVideoFile.getAbsolutePath());

        recorder.setVideoFrameRate(camcorderProfile.videoFrameRate);

          try {
              recorder.prepare();
          } 
          catch (IllegalStateException e) {
              Log.e("mytag", "IllegalStateException : " + Log.getStackTraceString(e)); }        
          catch (IOException e) { 
              Log.e("mytag", "IOException : " + Log.getStackTraceString(e)); } 

            recorder.start();
    }

........

........

现在我正在使用适用于Android 5.0的新存储访问框架选择一个文件夹:

    public void FolderSelection_Lollipop() {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
        startActivityForResult(intent, PICK_FOLDER_CODE_Lollipop);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent resultData) {  
        if(requestCode == PICK_FOLDER_CODE_Lollipop) {
            if(resultCode == RESULT_OK) {
                // Get Uri from Storage Access Framework.
                Uri Uri_Lollipop = resultData.getData();    
                VideoFolderAbsolutePATH = Uri_Lollipop.getPath();
                //also tried:
                VideoFolderAbsolutePATH = Uri_Lollipop.toString();

                // Persist access permissions.
                this.getContentResolver().takePersistableuriPermission(Uri_Lollipop,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }
    }

Recorder_Prepare()方法没有用,因为它在Android 5.0上给我IllegalStateException

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...