@Override public void run() { Message msg0 = new Message(); msg0.what = 0; mHandler.sendMessage(msg0); Log.v(TAG,"=mAccompanyPathpcm==="+mAccompanyPathpcm); File pcmFile = new File(mAccompanyPathpcm); Log.v(TAG,"=pcmFile==="+pcmFile); if(pcmFile.length() <= 0){ decode(mAccompanyPath,mAccompanyPathpcm); } Message msg1 = new Message(); msg1.what = 1; mHandler.sendMessage(msg1); isShow = false; // 播放和錄音準備 try { mMediaPlayer.prepare(); Log.v(TAG,"==mRecordPath==="+mRecordPath+"=mAccompanyPath=="+mAccompanyPath); mAccompany = new FileInputStream(mAccompanyPathpcm); mRecord = new FileOutputStream(mRecordPath); Log.v(TAG,"==1==lenth==="+mAccompany.getChannel().size()); mAccompany.read(header); Log.v(TAG,"==2==lenth==="+mAccompany.getChannel().size()); // mRecord.write(header); // mMediaPlayer.start(); isrun = true; lrc_timeend = 0; Log.v(TAG,"======SetlrcContent==start======="); viewlrcKLOK.SetlrcContent("準備好",0,0,"go,go,go..",0); Log.i(TAG, "========viewlrcKLOK==============start============================"); viewlrcKLOK.Star(); Log.i(TAG, "========viewlrcKLOK==============run============================"); // mMediaPlayer.prepare(); mMediaPlayer.start(); count = mMediaPlayer.getDuration(); Log.i(TAG, "========mMediaPlayerprepare==============start============================"+count); mHandler.sendEmptyMessage(2); mAudioRecord.startRecording(); mUpdateProgressHandler.post(mUpdateProgressRunnable); long AllFileSize = (mAccompany.getChannel().size() -44); Log.v(TAG,"===1===AllFileSize=="+AllFileSize); long CurrentRecorderSize = 0; boolean flag = false; // 邊錄音邊混合 // synchronized(mAudioRecord){ while (isRunning) { int rSize = mAudioRecord.read(recordBuf, 0, RecorderParameter.bufferSizeInBytes); // Log.v("H3c", "go:" + rSize); // float data= mMediaPlayer.getCurrentPosition()/count; // Log.v(TAG,"===1===count ====" + data); long CurrentFileSize =(long) ((mMediaPlayer.getCurrentPosition()*AllFileSize)/count); Log.v(TAG,"===1===CurrentFileSize=="+CurrentFileSize); if((CurrentFileSize%RecorderParameter.bufferSizeInBytes) > 0){ CurrentFileSize = (CurrentFileSize/RecorderParameter.bufferSizeInBytes)*RecorderParameter.bufferSizeInBytes; CurrentFileSize = CurrentFileSize + RecorderParameter.bufferSizeInBytes; } // Log.v(TAG,"===2===CurrentFileSize=="+CurrentFileSize); long tmp = CurrentFileSize - CurrentRecorderSize; while( tmp > 0 && flag == false){ // Log.v(TAG,"==tmp=="+tmp+"=CurrentFileSize="+CurrentFileSize + "=CurrentRecorderSize=="+CurrentRecorderSize); byte[] tmpbyte = new byte[(int)tmp]; int sizetmp = mAccompany.read(tmpbyte, 0, (int)tmp); CurrentRecorderSize = (CurrentRecorderSize +sizetmp); tmp = tmp -sizetmp; mRecord.write(tmpbyte, 0, (int)sizetmp); } int size = mAccompany.read(accompanyBuf, 0, rSize); if (size < 0) { isRunning = false; isrun = false; Log.v(TAG, "run======isRunning======="+isRunning); continue; } byte[] mixBuff = new byte[size]; //播放一包錄音 int j= 0; for (int i = 0; i < size; i++) { if(recordBuf[i] > 100 ){j++;} // if(recordBuf[i]< -1) // Log.v(TAG,"====i=="+i+"==recordBuf=="+recordBuf[i]); // j++; // if((j%2) == 1){ // // if(i <(size-1)){ // mixBuff[i] = accompanyBuf[i]; // mixBuff[i+1] = accompanyBuf[i+1]; // }else{ // mixBuff[i] = accompanyBuf[i]; // } // }else{ // if(i <(size-1)){ // mixBuff[i] = recordBuf[i]; // mixBuff[i+1] = recordBuf[i+1]; // }else{ // mixBuff[i] = recordBuf[i]; // } // } // mixBuff[i] = (byte) ((accompanyBuf[i]&0xf0f0)|(recordBuf[i]&0x0f0f)); // if(recordBuf[i] >= 0){ mixBuff[i] = (byte) Math .round(accompanyBuf[i]*0.4 + recordBuf[i]*0.6); // }else{ //// recordBuf[i] = 0; // mixBuff[i] = accompanyBuf[i]; // } } // Log.v(TAG,"===j=="+j); if( j > 10){ // Log.v(TAG,"===j=="+j); if(null != audioTrack){ audioTrack.write(recordBuf, 0, rSize); } mRecord.write(mixBuff); CurrentRecorderSize += mixBuff.length; flag = true; }else{ flag = false; mRecord.write(accompanyBuf); CurrentRecorderSize += accompanyBuf.length; } } if(ExitWithoutSaving){return;} } catch (IOException e) { Log.v("H3c", "=====catch==="+e); e.printStackTrace(); } finally { if(ExitWithoutSaving){return;} Log.v(TAG, "=====final====="+isRunning); if (mMediaPlayer != null) { mMediaPlayer.stop(); } if (mAudioRecord != null) { mAudioRecord.stop(); } if (viewlrcKLOK != null) { viewlrcKLOK.Stop(); } if(null != audioTrack){ audioTrack.stop(); } try { mAccompany.close(); mRecord.close(); } catch (IOException e) { e.printStackTrace(); } mUpdateProgressHandler .removeCallbacks(mUpdateProgressRunnable); // RemoveFile(mRecordPath); } copyWaveFile(mRecordPath, SavaAudioPath); RemoveFile(mRecordPath); // RemoveFile(mAccompanyPathpcm); Log.e(TAG, "=====run==end==========="); }