gpt4 book ai didi

JAVA错误: "E/MediaPlayer: Error (-38,0)"

转载 作者:行者123 更新时间:2023-12-01 21:58:16 25 4
gpt4 key购买 nike

我的 radio 有问题, radio 可以正常工作,但问题是,当我按下“暂停”时, radio 会停止,但是,当我再次单击“播放”时, radio 会再次启动,但就像它一样哪里有首歌。结论(抱歉我的解释不好)当我使用 OnPause() 时会发生这种情况奇怪的例子===

如果我开始播放下午 1:00,然后暂停下午 1:01,然后等待几分钟,然后再次播放, radio 将继续播放,就像下午 1:01 一样,现在是下午 1:05(尴尬的例子) )

当我更改为 OnStop() 时 它给了我 MediaPlayer 代码错误(-38,0)

enter code here :::::: b_play = findViewById(R.id.b_play);
b_play.setEnabled(false);
b_play.setText("Cargando...");

mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
new PlayerTask().execute(stream);

b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (started) {
started = false;
mediaPlayer.stop();
b_play.setText("Escuchar");

} else {
started = true;
mediaPlayer.start();
b_play.setText("Pausar");
}

}




@Override
protected Boolean doInBackground(String... strings) {
try {
mediaPlayer.setDataSource(strings[0]);
mediaPlayer.prepare();
prepared = true;

} catch (IOException e) {
e.printStackTrace();
}
return prepared;
}

@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
mediaPlayer.start();
b_play.setEnabled(true);
b_play.setText("Escuchar");


}

}

@Override
protected void onPause() {
super.onStop();
if (started) {
mediaPlayer.stop();
}
}

@Override
protected void onResume() {
super.onResume();
if (started) {
mediaPlayer.start();
}
}

@Override
protected void onDestroy() {
super.onDestroy();
if (prepared) {
mediaPlayer.release();
}

}

如果你能帮助我,我会很感激,我对我的英语和奇怪的解释感到抱歉(?

最佳答案

用 onStop 删除 onPause

@Override
protected void onStop() {
super.onStop();
if (started) {
mediaPlayer.stop();
}
}

@Override
protected void onResume() {
super.onResume();
if (started) {
mediaPlayer.start();
}
}

@Override
protected void onDestroy() {
super.onDestroy();
if (prepared) {
mediaPlayer.release();
}

}

关于JAVA错误: "E/MediaPlayer: Error (-38,0)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58722388/

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