當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioRecord.release方法代碼示例

本文整理匯總了Java中android.media.AudioRecord.release方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioRecord.release方法的具體用法?Java AudioRecord.release怎麽用?Java AudioRecord.release使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.AudioRecord的用法示例。


在下文中一共展示了AudioRecord.release方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createAudioRecord

import android.media.AudioRecord; //導入方法依賴的package包/類
/**
 * Creates a new {@link AudioRecord}.
 *
 * @return A newly created {@link AudioRecord}, or null if it cannot be created (missing
 * permissions?).
 */
private AudioRecord createAudioRecord() {
    for (int sampleRate : SAMPLE_RATE_CANDIDATES) {
        final int sizeInBytes = AudioRecord.getMinBufferSize(sampleRate, CHANNEL, ENCODING);
        if (sizeInBytes == AudioRecord.ERROR_BAD_VALUE) {
            continue;
        }
        final AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                sampleRate, CHANNEL, ENCODING, sizeInBytes);
        if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
            mBuffer = new byte[sizeInBytes];
            return audioRecord;
        } else {
            audioRecord.release();
        }
    }
    return null;
}
 
開發者ID:hsavaliya,項目名稱:GoogleAssistantSDK,代碼行數:24,代碼來源:VoiceRecorder_.java

示例2: RecognizerThread

import android.media.AudioRecord; //導入方法依賴的package包/類
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();
        }
    }
}
 
開發者ID:icaksama,項目名稱:RapidSphinx,代碼行數:19,代碼來源:RapidRecognizer.java

示例3: run

import android.media.AudioRecord; //導入方法依賴的package包/類
@Override
public void run() {
    byte[] buffer = new byte[audioBufferSize];
    recorder = new AudioRecord(audioSource, sampleRate, channel, audioFormat, audioBufferSize);
    try {
        while (recorder.getState() != AudioRecord.STATE_INITIALIZED)
            Thread.sleep(100, 0);
    } catch (InterruptedException e) {
        recorder.release();
        return;
    }

    recorder.startRecording();
    for (; ; ) {
        int length = recorder.read(buffer, 0, buffer.length);
        if (length < 0)
            Log.e("Record", "error: " + Integer.toString(length));
        else {
            for (WebSocket ws : wss)
                ws.sendBinary(buffer);
        }
        if (Thread.interrupted()) {
            recorder.stop();
            return;
        }
    }
}
 
開發者ID:zackszhu,項目名稱:hack_sjtu_2017,代碼行數:28,代碼來源:LiuLiShuo.java

示例4: start

import android.media.AudioRecord; //導入方法依賴的package包/類
public void start(){
    if(!isStarted){
        stopFlag=false;

        mRecordBufferSize = AudioRecord.getMinBufferSize(mRecordSampleRate,
                mRecordChannelConfig, mRecordAudioFormat)*2;
        mRecord=new AudioRecord(MediaRecorder.AudioSource.MIC,mRecordSampleRate,mRecordChannelConfig,
                mRecordAudioFormat,mRecordBufferSize);
        mRecord.startRecording();
        try {
            MediaFormat format=convertAudioConfigToFormat(mConfig.mAudio);
            mAudioEncoder=MediaCodec.createEncoderByType(format.getString(MediaFormat.KEY_MIME));
            mAudioEncoder.configure(format,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
            mAudioEncoder.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                while (!stopFlag&&!audioEncodeStep(false)){};
                audioEncodeStep(true);
                Log.e("wuwang","audio stop");
                if(isStarted){
                    mRecord.stop();
                    mRecord.release();
                    mRecord=null;
                }
                if(mAudioEncoder!=null){
                    mAudioEncoder.stop();
                    mAudioEncoder.release();
                    mAudioEncoder=null;
                }
                isStarted=false;
            }
        });
        thread.start();
        startTime=SystemClock.elapsedRealtimeNanos();
        isStarted=true;
    }
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:42,代碼來源:SoundRecorder.java

示例5: isCanUseAudio

import android.media.AudioRecord; //導入方法依賴的package包/類
/**
   * 判斷是是否有錄音權限
   */
  public static boolean isCanUseAudio(Activity activity) {
/*      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){//6.0以上係統
          if (ContextCompat.checkSelfPermission(activity,Manifest.permission.RECORD_AUDIO)!= PackageManager.PERMISSION_GRANTED) {
              return false;
          }else{
              return true;
          }

      }else {//6.0以下係統*/
      // 音頻獲取源
      int audioSource = MediaRecorder.AudioSource.MIC;
      // 設置音頻采樣率,44100是目前的標準,但是某些設備仍然支持22050,16000,11025
      int sampleRateInHz = 44100;
      // 設置音頻的錄製的聲道CHANNEL_IN_STEREO為雙聲道,CHANNEL_CONFIGURATION_MONO為單聲道
      int channelConfig = AudioFormat.CHANNEL_IN_STEREO;
      // 音頻數據格式:PCM 16位每個樣本。保證設備支持。PCM 8位每個樣本。不一定能得到設備支持。
      int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
      // 緩衝區字節大小
      int bufferSizeInBytes;
      bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz,
              channelConfig, audioFormat);
      AudioRecord audioRecord = new AudioRecord(audioSource, sampleRateInHz,
              channelConfig, audioFormat, bufferSizeInBytes);
      //開始錄製音頻
      try {
          // 防止某些手機崩潰,例如聯想
          audioRecord.startRecording();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }

      //根據開始錄音判斷是否有錄音權限
      if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
          // context.startActivity(new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS));
          return false;
      } else {
          audioRecord.stop();
          audioRecord.release();
          return true;
      }

      // }


  }
 
開發者ID:zhonglikui,項目名稱:cardinalsSample,代碼行數:49,代碼來源:DevicesUtil.java


注:本文中的android.media.AudioRecord.release方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。