2012-01-05 39 views
1

オーディオAudioTrackを処理するクラスを作成する必要があります。エンキュー、再生、停止、一時停止、再開を伴うAudioTrackクラス

このクラスには、オーディオトラックをエンキューして、同期して順番に再生するメソッドが必要です。

誰でもお手伝いできますか?

私はデキューを同期して知らず、オーディオの各部分を再生します。

byte []内のデータがaudiotrackに渡されるため、ファイルを使用しないでください。だから私はMediaPlayerを使用することはできません。あなたは、次のコードを使用することができます

答えて

1

...

bufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, 
       AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT); 

     if (bufferSize != AudioTrack.ERROR_BAD_VALUE && bufferSize != AudioTrack.ERROR) { 
      audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 
        this.sampleRateInHz, AudioFormat.CHANNEL_OUT_MONO, 
        AudioFormat.ENCODING_PCM_16BIT, this.bufferSize, 
        AudioTrack.MODE_STREAM); 
      if(audioTrack!=null && audioTrack.getState() == AudioTrack.STATE_INITIALIZED){ 
       Log.i(LOG_TAG,"Audio Track instance created buffer Size : "+this.bufferSize); 

       audioTrack.setPositionNotificationPeriod(320); 
       audioTrack.setPlaybackPositionUpdateListener(this); 
       audioTrack.play(); 
       short[] tempBuf =new short[bufferSize/2]; 

          // now write the code here to fill the tempBuf by reading from the file in shorts or bytes 
       audioTrack.write(tempBuf,0, tempBuf.length); 



      }else{ 
       Log.e(LOG_TAG,"Unble to create AudioTrack instance"); 
      } 
     } else { 
      Log.e(LOG_TAG, "Unable to get the minimum buffer size"); 
     } 
関連する問題