Code example for AudioRecord

Methods: getStatereleasestop

0
				} 
				(new File(filePath)).delete();
			} 
		} 
		if (audioRecorder != null) {
			audioRecorder.release();
		} 
	} 
	 
	/** 
	 *  
	 *  
	 * Resets the recorder to the INITIALIZING state, as if it was just created. 
	 * In case the class was in RECORDING state, the recording is stopped. 
	 * In case of exceptions the class is set to the ERROR state. 
	 *  
	 */ 
	public void reset() { 
		try { 
			if (state != State.ERROR) {
				release(); 
				audioRecorder = new AudioRecord(mAudioSource, mSampleRate, mChannelConfig, mAudioFormat, mBufferSize);
				if (audioRecorder.getState() != AudioRecord.STATE_INITIALIZED) {
					throw new Exception("AudioRecord initialization failed");
				} 
				audioRecorder.setRecordPositionUpdateListener(updateListener);
				audioRecorder.setPositionNotificationPeriod(mPeriodInFrames);
				state = State.INITIALIZING;
			} 
		} catch (Exception e) {
			Log.e(PcmAudioRecorder.class.getName(), e.getMessage());
			state = State.ERROR;
		} 
	} 
	 
	/** 
	 *  
	 *  
	 * Starts the recording, and sets the state to RECORDING. 
	 * Call after prepare(). 
	 *  
	 */ 
	public void start() { 
		if (state == State.READY) {
			audioRecorder.startRecording();
			audioRecorder.read(buffer, 0, buffer.length);	//[TODO: is this necessary]read the existing data in audio hardware, but don't do anything
			state = State.RECORDING;
		} else { 
			Log.e(PcmAudioRecorder.class.getName(), "start() called on illegal state");
			state = State.ERROR;
		} 
	} 
	 
	/** 
	 *  
	 *  
	 *  Stops the recording, and sets the state to STOPPED. 
	 * In case of further usage, a reset is needed. 
	 * Also finalizes the wave file in case of uncompressed recording. 
	 *  
	 */ 
	public void stop() { 
		if (state == State.RECORDING) {
			audioRecorder.stop();
			try { 
				mOutputStream.close();
			} catch(IOException e) {
				Log.e(PcmAudioRecorder.class.getName(), "I/O exception occured while closing output file");
				state = State.ERROR;