使用媒体记录器录制的视频已损坏

时间:2015-12-06 13:22:57

标签: android file video-capture mediarecorder

private boolean prepareMediaRecorder() {

这将获取文件的路径并将eye spy设置为文件夹的名称

        String path = String.valueOf(getOutputMediaFile(MEDIA_TYPE_VIDEO));
        File file = new File(path, "Eye Spy");
        mMediaRecorder = new MediaRecorder();

        try {
            mCamera.unlock();
        } catch (Exception ex) {
            return false;
        }
        // adjust the camera the way you need
        mMediaRecorder.setCamera(mCamera);
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

创建自定义的相机配置文件

        CamcorderProfile profile = CamcorderProfile.get(Camera.CameraInfo.CAMERA_FACING_BACK, CamcorderProfile.QUALITY_LOW);
        profile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
        profile.videoCodec = MediaRecorder.VideoEncoder.MPEG_4_SP;
        profile.videoFrameHeight = 240;
        profile.videoFrameWidth = 320;
        profile.videoBitRate = 15;
        mMediaRecorder.setProfile(profile);
        mMediaRecorder.setPreviewDisplay(mPreview.getSurface());

此行获取文件的路径并将其设置为输出

        mMediaRecorder.setOutputFile(file.getPath());

        //set max size
        mMediaRecorder.setMaxDuration(600000); // Set max duration 60 sec.
        mMediaRecorder.setMaxFileSize(50000000); // Set max file size 50M

        try {
            mMediaRecorder.prepare();
        } catch (Exception e) {
            releaseMediaRecorder();
            e.printStackTrace();
        }

为创建的文件夹创建缩略图,这是一个眼睛间谍

        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        Uri contentUri = Uri.fromFile(file);
        mediaScanIntent.setData(contentUri);
        getBaseContext().sendBroadcast(mediaScanIntent);

        return true;
    }

0 个答案:

没有答案