Video recording with media recorder

前端 未结 1 1142
不知归路
不知归路 2021-01-16 13:01

I am writing code for Video Recording function with Media recorder., But it throws Io Exception,Illegal State Exception i searched many times in google but no proper explan

相关标签:
1条回答
  • 2021-01-16 13:20

    Here is the code for recording video...

    recorder = new MediaRecorder();
            recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
            mPreview = new Preview(VideoRecorder.this,recorder);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            setContentView(mPreview);
    
    recorder.start();
    

    and here is the Preview Class....

    class Preview extends SurfaceView implements SurfaceHolder.Callback
    {
        SurfaceHolder mHolder;
        MediaRecorder tempRecorder;
        public Preview(Context context,MediaRecorder recorder) {
            super(context);
            tempRecorder=recorder;
            mHolder=getHolder();
            mHolder.addCallback(this);
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            // TODO Auto-generated constructor stub
        }
    
        public Surface getSurface()
        {
            return mHolder.getSurface();
        }
    
        public void surfaceCreated(SurfaceHolder holder){
            tempRecorder.setOutputFile("/sdcard/recordvideooutput.3gpp");
            tempRecorder.setPreviewDisplay(mHolder.getSurface());
            try{
                tempRecorder.prepare();
            } catch (Exception e) {
                String message = e.getMessage();
                tempRecorder.release();
                tempRecorder = null;
            }
        }
    
        public void surfaceDestroyed(SurfaceHolder holder) 
        {
            if(tempRecorder!=null)
            {
                tempRecorder.release();
                tempRecorder = null;
            }
        }
    
        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 
        {
    
        }
    }   
    
    0 讨论(0)
提交回复
热议问题