Code example for MediaRecorder: Recording audio and video

Methods: preparesetAudioEncodersetAudioSourcesetMaxDurationsetMaxFileSizesetOnErrorListenersetOnInfoListenersetOutputFilesetOutputFormatstart

0
			return -1; 
		} 
		 
		WazeLog.d( "Recoridng file to: " + aPath ); 
		 
		mMR = new MediaRecorder();
 
		mMR.setAudioSource( MediaRecorder.AudioSource.MIC );
		mMR.setOutputFormat( MediaRecorder.OutputFormat.MPEG_4 );
		mMR.setAudioEncoder( MediaRecorder.AudioEncoder.AMR_NB );
		mMR.setOutputFile( aPath );
		 
		mMR.setOnErrorListener( new OnErrorListener() );
		mMR.setOnInfoListener( new OnInfoListener() );
		mMR.setMaxDuration( (int) ( aTimeout * 1.05 ) );	// 5 Percent more
		mMR.setMaxFileSize( MAX_FILE_SIZE_BYTES );
		 
		/* 
		 * Increase sampling rate if possible 
		 */ 
//		final int sdkBuildVersion = Integer.parseInt( android.os.Build.VERSION.SDK ); 
//		if ( sdkBuildVersion >= android.os.Build.VERSION_CODES.FROYO ) 
//		{  
//			CompatabilityWrapper.setSamplingRate( mMR, SAMPLING_RATE ); 
//		} 
 
		try  
		{ 
			mMR.prepare();
			mMR.start();
		}  
		catch ( Exception ex ) 
		{ 
			WazeLog.ee( "Error starting media recorder", ex );
			res = -1;