本文整理汇总了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;
}