Best code examples for Android AudioRecord class (android.media.AudioRecord)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AudioRecord class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android AudioRecord examples from Open Source projects
This code example shows how to use the following methods: release, stop
	@Override 
	public void appStop(){ 
		threadRunning = false;
		 
		if(iTrack!=null){
			iTrack.stop();
		} 
		 
		try { 
			thread.join();
		} catch (InterruptedException e) {
			Log.e("OF", "error finishing audio thread ", e);
		} 
		thread = null;
		 
 
		if(oTrack!=null){
			oTrack.stop();
			oTrack.release();
			oTrack = null;

8
CodeRank
This code example shows how to use the following methods: getAudioFormat, getChannelCount, getSampleRate, release
										AudioFormat.ENCODING_PCM_8BIT;
 
		int minBufDevice = AudioRecord.getMinBufferSize(rate, channelConfig, encodingConfig);
		int minBufferSize = Math.max(bufsize * 8, minBufDevice + (bufsize - (minBufDevice % bufsize)));
		Log.i("SDL", "SDL: app opened recording device, rate " + rate + " channels " + channels + " sample size " + (encoding+1) + " bufsize " + bufsize + " internal bufsize " + minBufferSize);
		if( mRecorder == null || mRecorder.getSampleRate() != rate ||
			mRecorder.getChannelCount() != channels ||
			mRecorder.getAudioFormat() != encodingConfig ||
			mRecorderBufferSize != minBufferSize )
		{ 
			if( mRecorder != null )
				mRecorder.release();
			mRecorder = null;
			try { 
				mRecorder = new AudioRecord(AudioSource.DEFAULT, rate, channelConfig, encodingConfig, minBufferSize);
				mRecorderBufferSize = minBufferSize;
			} catch (IllegalArgumentException e) {
				Log.i("SDL", "SDL: error: failed to open recording device!");
				return null; 
			} 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getState, startRecording
 
		// ensure minimum record buffer 
		if (bufferSize < minimumBufferSize)
			bufferSize = minimumBufferSize;
 
		AudioRecord recorder = new AudioRecord(audioSource,
				sampleRateInHz, channelConfig, audioFormat, bufferSize);
 
		if (recorder.getState() != AudioRecord.STATE_INITIALIZED) {
			recorder.release();
			throw new IOException("Audio preparation failed");
		} 
 
		recorder.startRecording();
		this.audioRecorder = recorder;
		this.echoCanceller = echoCanceller;
	} 
 
	@Override 
	public void close() throws IOException { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getState, setPositionNotificationPeriod, setRecordPositionUpdateListener
				// Set frame period and timer interval accordingly 
				mPeriodInFrames = mBufferSize / ( 2 * mBitsPersample * mNumOfChannels / 8 );
				Log.w(PcmAudioRecorder.class.getName(), "Increasing buffer size to " + Integer.toString(mBufferSize));
			} 
			 
			audioRecorder = new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, mBufferSize);
			if (audioRecorder.getState() != AudioRecord.STATE_INITIALIZED) {
				throw new Exception("AudioRecord initialization failed");
			} 
			audioRecorder.setRecordPositionUpdateListener(updateListener);
			audioRecorder.setPositionNotificationPeriod(mPeriodInFrames);
			filePath = null;
			state = State.INITIALIZING;
		} catch (Exception e) {
			if (e.getMessage() != null) {
				Log.e(PcmAudioRecorder.class.getName(), e.getMessage());
			} else { 
				Log.e(PcmAudioRecorder.class.getName(), "Unknown error occured while initializing recording");
			} 
			state = State.ERROR;
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getRecordingState, getState, startRecording
    protected int getOutboundTimestamp() { 
        return (int) _countFrames * _audio.getFrameInterval();
    } 
 
    protected void startRec() { 
        if (_mic != null && _mic.getState() == AudioRecord.STATE_INITIALIZED) {
            Log.debug( 
                    this.getClass().getSimpleName()
                    + ".startRec(): starting mic"); 
            _mic.startRecording();
            resetTimestampRecStart(); 
            _countFrames = 0;
 
            Log.debug( 
                    this.getClass().getSimpleName() + ".startRec(): state="
                    + _mic.getState() + ", recordingState="
                    + _mic.getRecordingState());
 
            if (_me == null) {
                _me = new Thread(this, "mic");

8
CodeRank
Related Android AudioRecord Questions & Answers:
See Code Examples for Android AudioRecord Methods: