如何以编程方式在Android中捕获没有音频的视频?

时间:2017-02-17 08:30:54

标签: android audio video

我只是调用要捕获的视频意图。

`

private void dispatchTakeVideoIntent() {
       Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
}

`

像这样。但是我需要在没有Audio的情况下捕获它。我检查了下面这个链接,但是找不到如何解决 Android record video without audio

1 个答案:

答案 0 :(得分:0)

只需使用MediaRecorder类录制视频即可。使用媒体记录器,在设置音频和视频源时,不要在那里设置音频源。像这样。

public class MuteVideoRecorderView extends SurfaceView implements
        SurfaceHolder.Callback {

    private SurfaceHolder mHolder;

    private Camera mCamera;
    private MediaRecorder mMediaRecorder;

    public CamcorderView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mHolder = getHolder();
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mHolder.addCallback(this);

        mCamera = Camera.open();
        mRecorder = new MediaRecorder();

    }

    public void stop() {
        mRecorder.stop();
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {

        mCamera.unlock();
        mMediaRecorder.setCamera(mCamera);

        // Here we will not set mRecorder.setAudio(..);
        mMediaRecorder.setVideoSize(int, int);
        mMediaRecorder.setVideoFrameRate(int);

        mMediaRecorder.setPreviewDisplay(mHolder.getSurface());


        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

        // change for desired output folder
        mMediaRecorder.setOutputFile("/mnt/sdcard/test/work");

        try {
            mMediaRecorder.prepare();
        } catch (IllegalStateException e) {
            Log.e("IllegalStateException", e.toString());
        } catch (IOException e) {
            Log.e("IOException", e.toString());
        }
        mMediaRecorder.start();
    }
}