当前位置: 首页>>代码示例>>Java>>正文


Java AudioRecord.ERROR_INVALID_OPERATION属性代码示例

本文整理汇总了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();
    }
}
 
开发者ID:paozhuanyinyu,项目名称:XPermission,代码行数:25,代码来源:AudioRecordManager.java

示例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);
    }

}
 
开发者ID:ThinkKeep,项目名称:EvilsLive,代码行数:21,代码来源:AudioCapture.java

示例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;
}
 
开发者ID:suelensilva,项目名称:KaldiAndroid,代码行数:21,代码来源:RawAudioRecorder.java

示例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());
            }
        }
    }
}
 
开发者ID:pili-engineering,项目名称:PLDroidRTCStreaming,代码行数:16,代码来源:ExtAudioCapture.java

示例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());
        }
    }
}
 
开发者ID:sunshinecoast,项目名称:ScreenRecordCaptureMaster,代码行数:25,代码来源:YXMicRecorder.java

示例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;
}
 
开发者ID:ChillingVan,项目名称:AndroidInstantVideo,代码行数:37,代码来源:AACEncoder.java

示例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);

                }
            }
    }
 
开发者ID:ranatrk,项目名称:AudioGenderIdentifier,代码行数:15,代码来源:MainActivity.java


注:本文中的android.media.AudioRecord.ERROR_INVALID_OPERATION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。