Android上的ExtAudioRecorder问题

时间:2012-12-08 11:32:05

标签: android mediarecorder

我正在使用来自http://i-liger.com/article/android-wav-audio-recording的ExtAudioRecorder来录制WAV文件以进行进一步的音频处理。但是,有时我会收到这组错误消息:

12-08 18:58:18.217: E/AndroidRuntime(7323): FATAL EXCEPTION: main
12-08 18:58:18.217: E/AndroidRuntime(7323): java.lang.RuntimeException: Unable to start activity ComponentInfo{musicscoreify.app/musicscoreify.app.ReadWavFile}: java.lang.NullPointerException
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.os.Looper.loop(Looper.java:130)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.ActivityThread.main(ActivityThread.java:3691)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at java.lang.reflect.Method.invokeNative(Native Method)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at java.lang.reflect.Method.invoke(Method.java:507)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at dalvik.system.NativeStart.main(Native Method)
12-08 18:58:18.217: E/AndroidRuntime(7323): Caused by: java.lang.NullPointerException
12-08 18:58:18.217: E/AndroidRuntime(7323):     at musicscoreify.app.ReadWavFile.onCreate(ReadWavFile.java:138)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-08 18:58:18.217: E/AndroidRuntime(7323):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
12-08 18:58:18.217: E/AndroidRuntime(7323):     ... 11 more

因为ExtAudioRecorder中的一个方法崩溃了。方法如下:

public void onPeriodicNotification(AudioRecord recorder)
        {
            audioRecorder.read(buffer, 0, buffer.length); // Fill buffer
            try
            { 
                randomAccessWriter.write(buffer); // Write buffer to file
                payloadSize += buffer.length;
                if (bSamples == 16)
                {
                    for (int i=0; i<buffer.length/2; i++)
                    { // 16bit sample size
                        short curSample = getShort(buffer[i*2], buffer[i*2+1]);
                        if (curSample > cAmplitude)
                        { // Check amplitude
                            cAmplitude = curSample;
                        }
                    }
                }
                else    
                { // 8bit sample size
                    for (int i=0; i<buffer.length; i++)
                    {
                        if (buffer[i] > cAmplitude)
                        { // Check amplitude
                            cAmplitude = buffer[i];
                        }
                    }
                }
            }
            catch (IOException e)
            {
                Log.e(ExtAudioRecorder.class.getName(), "Error occured in updateListener, recording is aborted");
                //stop();
            }
        }

有没有人有类似的问题?我不知道为什么录音会被中止,为什么它只在某些时候发生。由于没有模式(或者至少我没有意识到是否存在模式)发生错误,因此我很难调试。如果有人可以帮我解决这个问题会很棒。

0 个答案:

没有答案