录制和播放音频时出错

时间:2011-10-12 10:47:20

标签: android voice-recording

我在http://androidgenuine.com/?tag=sound-record-android-modify-voice-on-android

中使用以下示例进行锻炼

我在这些

中有以下错误
while (isRecording) {
    // grab the buffered input (mic) and write it to a file on the SD
    int bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
    for (int i = 0; i< bufferReadResult; i++) {
    dos.writeShort(buffer[i]);
}

while (isPlaying) {
    for (int i = 0; i < bufferSize; i++) {
    // write the 'short' buffer blocks to the audiotrack
    try {
       short s = dis.readShort();
       buffer[i] = s;
    } catch (EOFException eofe) {
    isPlaying = false;
}

它的力量关闭,我的logcat是

<i>

10-13 12:32:06.710: ERROR/AndroidRuntime(1615): FATAL EXCEPTION: main
10-13 12:32:06.710: ERROR/AndroidRuntime(1615): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voicemodulation/com.voicemodulation.Voicemodulation}: java.lang.ClassCastException: android.widget.Button
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.os.Looper.loop(Looper.java:123)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.main(ActivityThread.java:3647)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at java.lang.reflect.Method.invokeNative(Native Method)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at java.lang.reflect.Method.invoke(Method.java:507)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at dalvik.system.NativeStart.main(Native Method)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615): Caused by: java.lang.ClassCastException: android.widget.Button
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at com.voicemodulation.Voicemodulation.onCreate(Voicemodulation.java:35)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     ... 11 more
10-13 12:32:06.731: WARN/ActivityManager(60):   Force finishing activity com.voicemodulation/.Voicemodulation
10-13 12:32:07.249: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{40731828 com.voicemodulation/.Voicemodulation}
10-13 12:32:15.125: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
10-13 12:32:16.305: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{40731828 com.voicemodulation/.Voicemodulation}
10-13 12:32:17.266: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{4060ebb8 com.example.calldemo/.Calldemo}
10-13 12:32:26.358: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{40731828 com.voicemodulation/.Voicemodulation}
</i>

2 个答案:

答案 0 :(得分:0)

&amp; lt少于符号“&lt;”在发布教程期间已经转换了脚本生成的html代码。所以你可以添加“&lt;”取代&amp; lt。

答案 1 :(得分:0)

问题似乎是因为此行中存在一些ClassCastException

10-13 12:32:06.710: ERROR/AndroidRuntime(1615): Caused by: java.lang.ClassCastException: android.widget.Button

也许你正试图错误地将一个小部件搞砸。检查语法。

对于前。

  Button b=(Button)findviewbyId(R.id.button);

可能被错误地初始化为,

  Button b=(TextView)findviewbyId(R.id.button);