录制和播放音频时出错
我在 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>
i workout with following example in http://androidgenuine.com/?tag=sound-record-android-modify-voice-on-android
I had following error in these
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]);
}
and
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;
}
Its force close and my logcat is
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
< 是小于号“<”在发布教程期间已将其转换为脚本生成的 html 代码。所以可以添加“<”代替 <。
< is the less then symbol "<" which has been converted script-generated html code during posting of tutorial. So you can add "<" in place of <.
问题似乎是因为这一行中的一些 ClassCastException
也许您正在尝试错误地强制转换小部件。检查语法。
对于前。
可能被错误地初始化为,
The problem appears to be because of some ClassCastException here in this line
Maybe you are trying to caste a widget wrongly. Check for the syntax.
For Ex.
could have been wrongly initialized as ,