0
私はAndroidのアプリケーションで同時にオーディオレコードを再生しようとしていますが、初めてコードが正常に動作してからクラッシュしています。以下のエラーが出ます。いずれかがこれを解決するか、これを解決する方法を提案してください。音声録音と再生ループバック問題
Error :
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40022178 self=0xce48
| sysTid=3508 nice=-19 sched=0/0 cgrp=[fopen-error:2] handle=-1345006496
| schedstat=(94146739 97717292 625)
at android.media.AudioTrack.native_write_byte(Native Method)
at android.media.AudioTrack.write(AudioTrack.java:912)
at com.brcm.factorymode.audioloop.speaker.RecordNPlay.loopback(RecordNPlay.java:102)
at com.brcm.factorymode.audioloop.speaker.RecordNPlay$1.run(RecordNPlay.java:131)
at com.brcm.factorymode.audioloop.speaker.RecordNPlay.do_loopback(RecordNPlay.java:136)
at com.brcm.factorymode.audioloop.speaker.RecordNPlay.onCreate(RecordNPlay.java:53)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
下記のコードを確認してください。
public void loopback() {
buffer = new byte[BUF_SIZE];
// Prepare the AudioRecord & AudioTrack
Log.e("LOG", "Entered into loopback function....");
try {
buffersize = AudioRecord.getMinBufferSize(SAMPLE_RATE,AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
} catch (Throwable t) {
Log.e("Audio", "Buffer size failed");
}
if (buffersize <= BUF_SIZE) {
buffersize = BUF_SIZE;
}
try {
//findAudioRecord();
m_record = new AudioRecord(MediaRecorder.AudioSource.MIC,
SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, buffersize * 1);
m_track = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, buffersize * 1,
AudioTrack.MODE_STREAM);
m_track.setPlaybackRate(SAMPLE_RATE);
Log.e("LOG", "INITIALIZATIONS DONE....");
} catch (Throwable t) {
Log.e("Audio", "Audio Failed");
}
if(m_record!=null)
if (m_record.getState() == AudioRecord.STATE_INITIALIZED)
m_record.startRecording();
if(m_track!=null)
if (m_track.getState() == AudioTrack.STATE_INITIALIZED)
m_track.play();
try {
int i = 0;
while (i<=10) {
// buffer=new byte[buffersize];
m_record.read(buffer, 0, buffersize);
m_track.write(buffer, 0, buffersize);
//m_track.flush();
/* try{
Thread.sleep(200);
}catch(Exception e){}
*/
i++;
}
if (i>10) {
buffer = null;
m_record.stop();
m_track.stop();
i=0;
}
} catch (Exception e) {
Log.e("Em_recordRROR", "exception: " + e.getLocalizedMessage());
}
Log.i("D2Record", "loopback exit");
}
private void do_loopback() {
m_thread = new Runnable() {
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
m_isRun = true;
loopback();
}
};
m_thread.run();
}
plz私の質問に見て、同様の問題で私を助けてくださいhttp://stackoverflow.com/questions/9413998/live-audio-recording-and-playing-in-android – aProgrammer