Code example for MediaRecorder: Recording audio and video

Methods: preparesetAudioChannelssetAudioEncodersetAudioEncodingBitRatesetAudioSamplingRatesetAudioSourcesetOutputFilesetOutputFormatstart

0
		}	 
	} 
	boolean recordingStarted = false;
	try { 
		// TODO file validation checks 
		recorder = new MediaRecorder();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
		recorder.setOutputFile(filePath);
 
		// TODO these may change --> 
		recorder.setAudioChannels(audioChannels);
		recorder.setAudioSamplingRate(samplingRate);
		recorder.setAudioEncodingBitRate(encodingBitRate);
		// <----- 
 
		try { 
			System.out.println("Preparing recorder.....");
			recorder.prepare();
		} catch (IllegalStateException e) {
			System.out
					.println("While preparing recorder...Error Occured !!");
			e.printStackTrace();
			throw e;
		} catch (IOException e) {
			System.out
					.println("While preparing recorder...Error Occured !!");
			e.printStackTrace();
			throw e;
		} 
 
		System.out.println("Starting recorder.....");
		recorder.start(); // Recording is now started
 
		recordingStarted = true;
	} catch (Exception e) {
	}