本文整理匯總了Java中android.media.AudioRecord.STATE_UNINITIALIZED屬性的典型用法代碼示例。如果您正苦於以下問題:Java AudioRecord.STATE_UNINITIALIZED屬性的具體用法?Java AudioRecord.STATE_UNINITIALIZED怎麽用?Java AudioRecord.STATE_UNINITIALIZED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.media.AudioRecord
的用法示例。
在下文中一共展示了AudioRecord.STATE_UNINITIALIZED屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: RecognizerThread
public RecognizerThread(int timeout) {
if (timeout != NO_TIMEOUT) {
this.timeoutSamples = timeout * sampleRate / 1000;
} else {
this.timeoutSamples = NO_TIMEOUT;
}
this.remainingSamples = this.timeoutSamples;
recorder = new AudioRecord(6, sampleRate, 16, 2, bufferSize * 2);
if (recorder.getState() == AudioRecord.STATE_UNINITIALIZED) {
recorder.release();
try {
throw new IOException(
"Failed to initialize recorder. Microphone might be already in use.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例2: stopAndRelease
/**
* Stop and release resource.
*
*/
public void stopAndRelease() {
if ((mAudioRecord != null) && (mAudioRecord.getState() != AudioRecord.STATE_UNINITIALIZED)) {
try {
mAudioRecord.stop();
mAudioRecord.release();
} catch (Exception e) {
Log.e(TAG, "stopAndRelease() Exception: " + e.getMessage());
}
}
mAudioRecord = null;
}
示例3: startCapture
public boolean startCapture(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) {
if (mIsCaptureStarted) {
Log.e(TAG, "Capture already started !");
return false;
}
int minBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
if (minBufferSize == AudioRecord.ERROR_BAD_VALUE) {
Log.e(TAG, "Invalid parameter !");
return false;
}
mAudioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, minBufferSize * 4);
if (mAudioRecord.getState() == AudioRecord.STATE_UNINITIALIZED) {
Log.e(TAG, "AudioRecord initialize fail !");
return false;
}
mAudioRecord.startRecording();
mIsLoopExit = false;
mCaptureThread = new Thread(new AudioCaptureRunnable());
mCaptureThread.start();
mIsCaptureStarted = true;
Log.d(TAG, "Start audio capture success !");
return true;
}
示例4: stop
public void stop() {
if (recorder != null
&& recorder.getState() != AudioRecord.STATE_UNINITIALIZED) {
recorder.stop();
recorder.release();
Log.i("AudioCodec", "Sampling stopped");
}
Log.i("AudioCodec", "Recorder set to null");
recorder = null;
}
示例5: initialise
/**
* Initialise the Voice Recorder
*
* @return The audio record initialisation state.
*/
public int initialise() {
int count = 0;
while (count < 4) {
count++;
saiyAudio = new SaiyAudio(audioSource, sampleRateInHz, channelConfig, audioFormat,
bufferSizeInBytes, enhance);
if (saiyAudio.getState() == AudioRecord.STATE_INITIALIZED) {
return AudioRecord.STATE_INITIALIZED;
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "SaiyAudio reinitialisation attempt ~ " + count);
}
if (Looper.myLooper() != null && Looper.myLooper() != Looper.getMainLooper()) {
// Give the audio object a small chance to sort itself out
try {
Thread.sleep(250);
} catch (InterruptedException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "SaiyAudio InterruptedException");
e.printStackTrace();
}
}
}
}
}
if (DEBUG) {
MyLog.w(CLS_NAME, "SaiyAudio initialisation failed");
}
return AudioRecord.STATE_UNINITIALIZED;
}
示例6: startCapture
public boolean startCapture(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) {
if (mIsCaptureStarted) {
Log.e(TAG, "hujd Capture already started !");
return false;
}
mMinBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
if (mMinBufferSize == AudioRecord.ERROR_BAD_VALUE) {
Log.e(TAG, "hujd Invalid parameter !");
return false;
}
Log.e(TAG, "hujd getMinBufferSize = " + mMinBufferSize + " bytes !");
mAudioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, mMinBufferSize);
if (mAudioRecord.getState() == AudioRecord.STATE_UNINITIALIZED) {
Log.e(TAG, "hujd AudioRecord initialize fail !");
return false;
}
mAudioRecord.startRecording();
mIsLoopExit = false;
mCaptureThread = new Thread(new AudioCaptureRunnable());
mCaptureThread.start();
mIsCaptureStarted = true;
Log.e(TAG, "hujd Start audio capture success !");
return true;
}