gpt4 book ai didi

Android MediaPlayer 准备失败 : status = 0x1

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:37 24 4
gpt4 key购买 nike

我正在构建一个需要回放录制声音的录音机。我在播放音频时遇到了很多麻烦。我知道该文件存在,因为我将它隔离到我的 SD 卡上的一个文件夹中,但由于某种原因它无法播放它。

这是我的代码:

public class RecorderEditActivity extends SherlockActivity implements
DatabaseHelper.MetadataListener {

private long position;

private Button playButton = null;
private TextView date = null;
private EditText title = null;
private EditText notes = null;
private Button saveButton = null;

private MediaPlayer mediaPlayer = null;
private boolean isPlaying = false;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.edit_item);

position = getIntent().getExtras().getLong(DatabaseHelper.KEY_ROWID);

playButton = (Button) findViewById(R.id.play);
date = (TextView) findViewById(R.id.recording_date);
title = (EditText) findViewById(R.id.edit_title);
notes = (EditText) findViewById(R.id.edit_notes);
saveButton = (Button) findViewById(R.id.save_edit_button);

mediaPlayer = new MediaPlayer();

DatabaseHelper.getInstance(getApplicationContext()).getMetadataAsync(
position, this);

playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isPlaying) {
playButton.setText(R.string.stop_text);
try {
mediaPlayer = new MediaPlayer();
mediaPlayer
.setDataSource("sdcard/test/"
+ date.toString() + ".3gp");
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
}
});
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage(), e);
}
} else {
playButton.setText(R.string.play_text);
mediaPlayer.release();
}
isPlaying = !isPlaying;
}
});

这是来自 LogCat 的错误:

03-20 00:33:40.963: E/MediaPlayer(21268): error (1, -2147483648)
03-20 00:33:40.963: E/java.io.IOException(21268): Prepare failed.: status=0x1
03-20 00:33:40.963: E/java.io.IOException(21268): java.io.IOException: Prepare failed.: status=0x1
03-20 00:33:40.963: E/java.io.IOException(21268): at android.media.MediaPlayer.prepare(Native Method)
03-20 00:33:40.963: E/java.io.IOException(21268): at com.packagename.soundrecorder.RecorderEditActivity$1.onClick(RecorderEditActivity.java:56)
03-20 00:33:40.963: E/java.io.IOException(21268): at android.view.View.performClick(View.java:4204)
03-20 00:33:40.963: E/java.io.IOException(21268): at android.view.View$PerformClick.run(View.java:17355)
03-20 00:33:40.963: E/java.io.IOException(21268): at android.os.Handler.handleCallback(Handler.java:725)
03-20 00:33:40.963: E/java.io.IOException(21268): at android.os.Handler.dispatchMessage(Handler.java:92)
03-20 00:33:40.963: E/java.io.IOException(21268): at android.os.Looper.loop(Looper.java:137)
03-20 00:33:40.963: E/java.io.IOException(21268): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-20 00:33:40.963: E/java.io.IOException(21268): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 00:33:40.963: E/java.io.IOException(21268): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 00:33:40.963: E/java.io.IOException(21268): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-20 00:33:40.963: E/java.io.IOException(21268): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-20 00:33:40.963: E/java.io.IOException(21268): at dalvik.system.NativeStart.main(Native Method)

希望有人能帮我解释和解决这个问题。我做了很多研究,但我所做的一切都无济于事。谢谢:)

最佳答案

我想通了:像往常一样愚蠢的错误。我忘了添加读取外部存储器的权限,由于您在上面的评论,我要感谢瓦西里的修复。另一件事是我没有在我的日期 TextView 上调用 getText(),所以它没有正确设置文件名。

关于Android MediaPlayer 准备失败 : status = 0x1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15511939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com