本文整理汇总了Java中android.media.AudioRecord.ERROR_INVALID_OPERATION属性的典型用法代码示例。如果您正苦于以下问题:Java AudioRecord.ERROR_INVALID_OPERATION属性的具体用法?Java AudioRecord.ERROR_INVALID_OPERATION怎么用?Java AudioRecord.ERROR_INVALID_OPERATION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.media.AudioRecord
的用法示例。
在下文中一共展示了AudioRecord.ERROR_INVALID_OPERATION属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
@Override
public void run() {
try {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
int bytesRecord;
byte[] tempBuffer = new byte[bufferSize];
mRecorder.startRecording();
while (isStart) {
if (mRecorder != null) {
bytesRecord = mRecorder.read(tempBuffer, 0, bufferSize);
if (bytesRecord == AudioRecord.ERROR_INVALID_OPERATION || bytesRecord ==
AudioRecord.ERROR_BAD_VALUE) {
continue;
}
if (bytesRecord != 0 && bytesRecord != -1) {
dos.write(tempBuffer, 0, bytesRecord);
} else {
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: run
@Override
public void run() {
while (!mIsLoopExit) {
byte[] buffer = new byte[mMinBufferSize];
int ret = mAudioRecord.read(buffer, 0, mMinBufferSize);
if (ret == AudioRecord.ERROR_INVALID_OPERATION) {
Log.e(TAG, "Error ERROR_INVALID_OPERATION");
} else if (ret == AudioRecord.ERROR_BAD_VALUE) {
Log.e(TAG, "Error ERROR_BAD_VALUE");
} else {
if (mAudioFrameCapturedListener != null) {
mAudioFrameCapturedListener.onAudioFrameCaptured(buffer);
}
Log.d(TAG, "OK, Captured " + ret + " bytes !");
}
SystemClock.sleep(10);
}
}
示例3: read
private int read(AudioRecord recorder) {
int numberOfBytes = recorder.read(mBuffer, 0, mBuffer.length); // Fill buffer
// Some error checking
if (numberOfBytes == AudioRecord.ERROR_INVALID_OPERATION) {
Log.e(LOG_TAG, "The AudioRecord object was not properly initialized");
return -1;
} else if (numberOfBytes == AudioRecord.ERROR_BAD_VALUE) {
Log.e(LOG_TAG, "The parameters do not resolve to valid data and indexes.");
return -2;
} else if (numberOfBytes > mBuffer.length) {
Log.e(LOG_TAG, "Read more bytes than is buffer length:" + numberOfBytes + ": " + mBuffer.length);
return -3;
} else if (numberOfBytes == 0) {
Log.e(LOG_TAG, "Read zero bytes");
return -4;
}
// Everything seems to be OK, adding the buffer to the recording.
add(mBuffer);
return 0;
}
示例4: run
@Override
public void run() {
while (!mIsLoopExit) {
byte[] buffer = new byte[SAMPLES_PER_FRAME * 2];
int ret = mAudioRecord.read(buffer, 0, buffer.length);
if (ret == AudioRecord.ERROR_INVALID_OPERATION) {
Log.e(TAG, "Error ERROR_INVALID_OPERATION");
} else if (ret == AudioRecord.ERROR_BAD_VALUE) {
Log.e(TAG, "Error ERROR_BAD_VALUE");
} else {
if (mOnAudioFrameCapturedListener != null) {
mOnAudioFrameCapturedListener.onAudioFrameCaptured(buffer, System.nanoTime());
}
}
}
}
示例5: record
public void record() {
final ByteBuffer bytebuffer = ByteBuffer.allocateDirect(SAMPLES_PER_FRAME);
int bufferReadResult;
while (isRecording) {
bytebuffer.clear();
bufferReadResult = mAudioRecord.read(bytebuffer, SAMPLES_PER_FRAME);
if (bufferReadResult == AudioRecord.ERROR_INVALID_OPERATION || bufferReadResult == AudioRecord.ERROR_BAD_VALUE) {
} else if (bufferReadResult >= 0) {
//LogUtil.d(TAG, "bytes read "+bufferReadResult);
// todo send this byte array to an audio encoder
bytebuffer.position(bufferReadResult);
bytebuffer.flip();
byte[] bytes = new byte[bytebuffer.remaining()];
bytebuffer.get(bytes);
bytebuffer.position(bufferReadResult);
bytebuffer.flip();
yixiaAudioEncoder.encode(bytebuffer, bufferReadResult, yixiaAudioEncoder.getPTSUs());
}
}
}
示例6: start
public void start() {
mAudioRecord.startRecording();
mMediaCodec.start();
final long startWhen = System.nanoTime();
final ByteBuffer[] inputBuffers = mMediaCodec.getInputBuffers();
mThread = new Thread(new Runnable() {
@Override
public void run() {
int len, bufferIndex;
while (isStart && !Thread.interrupted()) {
synchronized (mMediaCodec) {
if (!isStart) return;
bufferIndex = mMediaCodec.dequeueInputBuffer(10000);
if (bufferIndex >= 0) {
inputBuffers[bufferIndex].clear();
long presentationTimeNs = System.nanoTime();
len = mAudioRecord.read(inputBuffers[bufferIndex], bufferSize);
presentationTimeNs -= (len / samplingRate ) / 1000000000;
Loggers.i(TAG, "Index: " + bufferIndex + " len: " + len + " buffer_capacity: " + inputBuffers[bufferIndex].capacity());
long presentationTimeUs = (presentationTimeNs - startWhen) / 1000;
if (len == AudioRecord.ERROR_INVALID_OPERATION || len == AudioRecord.ERROR_BAD_VALUE) {
Log.e(TAG, "An error occured with the AudioRecord API !");
} else {
mMediaCodec.queueInputBuffer(bufferIndex, 0, len, presentationTimeUs, 0);
if (onDataComingCallback != null) {
onDataComingCallback.onComing();
}
}
}
}
}
}
});
mThread.start();
isStart = true;
}
示例7: writeAudioDataToArrayList
private void writeAudioDataToArrayList(){
short data[] = new short[bufferSize];
int read = 0;
while(isRecording){
read = recorder.read(data, 0, bufferSize);
if(AudioRecord.ERROR_INVALID_OPERATION != read){
dataArrayList.add(data);
}
}
}