public void prepare() {try{if(state ==State.INITIALIZING){audioRecorder.setRecordPositionUpdateListener(updateListener); audioRecorder.setPositionNotificationPeriod(framePeriod);if((audioRecorder.getState()==AudioRecord.STATE_INITIALIZED)&(filePath !=null)){// write file headerOutputStreamout=newFileOutputStream(filePath);out.write(1);out.close(); random =newRandomAccessFile(filePath,"rw"); random.setLength(0);// Set file length to random.writeBytes("RIFF");
......
具体细节如下
audioRecorder1=AudioRecorder1.getInstanse();HandlerThread handlerThread=newHandlerThread("handlerThread"); handlerThread.start();try{Field field=audioRecorder1.getClass().getDeclaredField("audioRecorder");Field field2=field.getType().getDeclaredField("mInitializationLooper"); field.setAccessible(true); field2.setAccessible(true);System.out.println("--handlerThread-lp--"+handlerThread.getLooper());System.out.println("--main-lp--"+Looper.getMainLooper()); field2.set(field.get(audioRecorder1), handlerThread.getLooper()); audioRecorder1.setOutputFile("/mnt/sdcard/audio11.wav"); audioRecorder1.prepare(); audioRecorder1.start();}catch(NoSuchFieldException e){// TODO Auto-generated catch block e.printStackTrace();}catch(IllegalArgumentException e){// TODO Auto-generated catch block e.printStackTrace();}catch(IllegalAccessException e){// TODO Auto-generated catch block e.printStackTrace();}