Code example for MediaRecorder: Recording audio and video

Methods: preparereleaseresetsetPreviewDisplaystart

0
        myMediaRecorder.setProfile(targetProfile);
    } 
    
    private boolean realyStart() { 
         
        myMediaRecorder.setPreviewDisplay(myCamSHolder.getSurface());
        try { 
        	myMediaRecorder.prepare();
	    } catch (IllegalStateException e) {
	        releaseMediaRecorder();	 
	        Log.d("TEAONLY", "JAVA:  camera prepare illegal error");
            return false; 
	    } catch (IOException e) {
	        releaseMediaRecorder();	     
	        Log.d("TEAONLY", "JAVA:  camera prepare io error");
            return false; 
	    } 
	     
        try { 
            myMediaRecorder.start();
        } catch( Exception e) {
            releaseMediaRecorder(); 
	        Log.d("TEAONLY", "JAVA:  camera start error");
            return false; 
        } 
 
        return true; 
    } 
 
    public boolean StartStreaming(FileDescriptor targetFd) {
        myMediaRecorder.setOutputFile(targetFd);
        myMediaRecorder.setMaxDuration(7200000); 	// Set max duration 2 hours
        myMediaRecorder.setMaxFileSize(1600000000); // Set max file size 16G
         
        myMediaRecorder.setOnInfoListener(streamingEventHandler);
        return realyStart(); 
    } 
 
    public boolean StartRecording(String targetFile) {
         
        myMediaRecorder.setOutputFile(targetFile);
        myMediaRecorder.setMaxDuration(7200000); 	// Set max duration 2 hours
        myMediaRecorder.setMaxFileSize(400000000); // Set max file size 4G
                 
        return realyStart(); 
    } 
     
    public void StopMedia() { 
        myMediaRecorder.stop();
        releaseMediaRecorder();         
    } 
 
    private void releaseMediaRecorder(){ 
        if (myMediaRecorder != null) {
        	myMediaRecorder.reset();   // clear recorder configuration
        	myMediaRecorder.release(); // release the recorder object
        	myMediaRecorder = null;
            myCamera.lock();           // lock camera for later use
            myCamera.startPreview();
        } 
        myMediaRecorder = null;