本文整理汇总了Java中android.media.AudioRecord.RECORDSTATE_RECORDING属性的典型用法代码示例。如果您正苦于以下问题:Java AudioRecord.RECORDSTATE_RECORDING属性的具体用法?Java AudioRecord.RECORDSTATE_RECORDING怎么用?Java AudioRecord.RECORDSTATE_RECORDING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.media.AudioRecord
的用法示例。
在下文中一共展示了AudioRecord.RECORDSTATE_RECORDING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
/**
* <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);
}
}
示例2: stop
/**
* <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();
mRecorder.release();
setState(State.STOPPED);
} catch (IllegalStateException e) {
Log.e(LOG_TAG, "native stop() called in illegal state: " + e.getMessage());
setState(State.ERROR);
}
} else {
Log.e(LOG_TAG, "stop() called in illegal state");
setState(State.ERROR);
}
}
示例3: listen
public byte[] listen() {
mReceivedBytes = new byte[]{};
mFinished = false;
if (mAudioRec.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
mAudioRec.startRecording();
}
while (true) {
if (mFinished) break;
// short[] audioData = readAudioData();
// window(audioData);
//
// int[] powerlist = new int[18];
// for (int i = 0; i < powerlist.length; i++) {
// powerlist[i] = goertzel(CHAR_FREQ[i]);
// }
// int base = goertzel(BASELINE);
//
// updateState(powerlist, base);
// signalToBits();
// processByte();
}
return mReceivedBytes;
}
示例4: isRecodingStopped
private boolean isRecodingStopped() {
if (mRecordState == RecordState.STOPPING) {
// AudioRecord has been released, it means recorder thread is stopped.
if (mRecord == null) {
return true;
} else {
// Check AudioRecord state if recorder thread is still running.
if (mRecord.getState() != AudioRecord.RECORDSTATE_RECORDING) {
return true;
}
}
} else if (mRecordState == RecordState.STOPPED) {
return true;
}
return false;
}
示例5: stopCapture
public void stopCapture() {
if (!mIsCaptureStarted) {
return;
}
mIsLoopExit = true;
try {
mCaptureThread.interrupt();
mCaptureThread.join(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
mAudioRecord.stop();
}
mAudioRecord.release();
mIsCaptureStarted = false;
mOnAudioFrameCapturedListener = null;
Log.d(TAG, "Stop audio capture success !");
}
示例6: start
public void start()
{
if(getState()==AudioRecord.STATE_INITIALIZED)
{
startRecording();
if(getRecordingState()==AudioRecord.RECORDSTATE_RECORDING)
{
new Thread() {
public void run() {
recorderLoop();
}
}.start();
} else {
Log.e("startRecording()"," failed");
}
} else {
Log.e("start()"," called on illegal state");
}
}
示例7: startRecording
private boolean startRecording() {
Logging.d(TAG, "startRecording");
assertTrue(audioRecord != null);
assertTrue(audioThread == null);
try {
audioRecord.startRecording();
} catch (IllegalStateException e) {
reportWebRtcAudioRecordStartError("AudioRecord.startRecording failed: " + e.getMessage());
return false;
}
if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
reportWebRtcAudioRecordStartError("AudioRecord.startRecording failed - incorrect state :"
+ audioRecord.getRecordingState());
return false;
}
audioThread = new AudioRecordThread("AudioRecordJavaThread");
audioThread.start();
return true;
}
示例8: stopCapture
public void stopCapture() {
if (!mIsCaptureStarted) {
return;
}
mIsLoopExit = true;
try {
mCaptureThread.interrupt();
mCaptureThread.join(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
mAudioRecord.stop();
}
mAudioRecord.release();
mIsCaptureStarted = false;
mAudioFrameCapturedListener = null;
Log.d(TAG, "Stop audio capture success !");
}
示例9: stopAudioRecord
private boolean stopAudioRecord(Context context)
{
try
{
if (audioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
{
isAudioRecordRunning = false;
audioRecord.setRecordPositionUpdateListener(null);
audioRecord.stop();
audioRecordRandomAccessFile.seek(4);
audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(36 + audioRecordPayloadSize)); // 04 - Size of the overall file
audioRecordRandomAccessFile.seek(40);
audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(audioRecordPayloadSize)); // 40 - Size of the data section
audioRecordRandomAccessFile.close();
}
}
catch (Exception e)
{
Log.w("RecordFileWriter", "stopAudioRecord : " + context.getString(R.string.log_record_file_writer_error_stop_audiorecord) + " : " + e);
databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_stop_audiorecord), new Date().getTime(), 2, false);
return false;
}
return true;
}
示例10: release
/**
* <p>Stops the recording (if needed) and releases the resources.
* 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;
}
}
示例11: recorderLoop
private void recorderLoop() {
while (getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
int status = read(mBuffer);
if (status < 0) {
Log.e("status = ", String.valueOf(status));
break;
}
}
}
示例12: startRecording
private boolean startRecording() {
threadChecker.checkIsOnValidThread();
Logging.d(TAG, "startRecording");
assertTrue(audioRecord != null);
assertTrue(audioThread == null);
// Starts recording from the AudioRecord instance.
try {
audioRecord.startRecording();
} catch (IllegalStateException e) {
reportWebRtcAudioRecordStartError(AudioRecordStartErrorCode.AUDIO_RECORD_START_EXCEPTION,
"AudioRecord.startRecording failed: " + e.getMessage());
return false;
}
// Verify the recording state up to two times (with a sleep in between)
// before returning false and reporting an error.
int numberOfStateChecks = 0;
while (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING &&
++numberOfStateChecks < 2) {
threadSleep(200);
}
if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
reportWebRtcAudioRecordStartError(
AudioRecordStartErrorCode.AUDIO_RECORD_START_STATE_MISMATCH,
"AudioRecord.startRecording failed - incorrect state :"
+ audioRecord.getRecordingState());
return false;
}
// Create and start new high-priority thread which calls AudioRecord.read()
// and where we also call the native DataIsRecorded() callback to feed
// WebRTC with recorded audio.
audioThread = new AudioRecordThread("AudioRecordJavaThread");
audioThread.start();
return true;
}
示例13: releaseAudioRecord
private boolean releaseAudioRecord(Context context)
{
try
{
if (audioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
{
stopAudioRecord(context);
}
else if(audioRecord.getState() == AudioRecord.STATE_INITIALIZED)
{
audioRecordRandomAccessFile.close();
}
if (audioRecord != null)
{
audioRecord.release();
}
}
catch (Exception e)
{
Log.w("RecordFileWriter", "releaseAudioRecord : " + context.getString(R.string.log_record_file_writer_error_release_audiorecord) + " : " + e);
databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_release_audiorecord), new Date().getTime(), 2, false);
return false;
}
return true;
}
示例14: isRecord
public boolean isRecord() {
return running.get() && mRecorder.getStatus() == AudioRecord.RECORDSTATE_RECORDING;
}
示例15: startRecording
public void startRecording() {
if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
return;
mAudioRecord.startRecording();
}