當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。