Code example for AudioRecord

Methods: getRecordingStategetStatereleasestop

0
	 * The object can no longer be used and the reference should be 
	 * set to null after a call to release().</p> 
	 */ 
	public synchronized void release() { 
		if (mRecorder != null) {
			if (mRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
				stop(); 
			} 
			mRecorder.release();
			mRecorder = null;
		} 
	} 
 
 
	/** 
	 * <p>Starts the recording, and sets the state to RECORDING.</p> 
	 */ 
	public void start() { 
		if (mRecorder.getState() == AudioRecord.STATE_INITIALIZED) {
			mRecorder.startRecording();
			if (mRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
				setState(State.RECORDING);
				new Thread() {
					public void run() { 
						while (mRecorder != null && mRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
							int status = read(mRecorder);
							if (status < 0) {
								break; 
							} 
						} 
					} 
				}.start();
			} else { 
				Log.e(LOG_TAG, "startRecording() failed");
				setState(State.ERROR);
			} 
		} else { 
			Log.e(LOG_TAG, "start() called on illegal state");
			setState(State.ERROR);
		} 
	} 
 
 
	/** 
	 * <p>Stops the recording, and sets the state to STOPPED. 
	 * If stopping fails then sets the state to ERROR.</p> 
	 */ 
	public void stop() { 
		// We check the underlying AudioRecord state trying to avoid IllegalStateException. 
		// If it still occurs then we catch it. 
		if (mRecorder.getState() == AudioRecord.STATE_INITIALIZED &&
				mRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
			try { 
				mRecorder.stop();
				setState(State.STOPPED);
			} catch (IllegalStateException e) {
				Log.e(LOG_TAG, "native stop() called in illegal state: " + e.getMessage());
				setState(State.ERROR);
			}