gpt4 book ai didi

java - setOnCompletionListener 不起作用

转载 作者:行者123 更新时间:2023-12-01 06:10:02 26 4
gpt4 key购买 nike

我有一个 MediaPlayer 的 onCompletion 监听器,但在 MediaPlayer 停止后它无法工作,并且会导致错误。我想在音频停止后更改按钮背景;这是代码:

  btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isPlaying == false) {
isPlaying = true;
try {
if (mp.isPlaying()) {
mp.stop();
mp.release();
}
btnPlay.setBackgroundResource(R.drawable.stop_play_button);
mp = MediaPlayer.create(getApplicationContext(), path[flag]);
mp.start();
} catch (Exception e) {
e.printStackTrace();
}
} else {
isPlaying = false;
mp.stop();
mp.release();
btnPlay.setBackgroundResource(R.drawable.play_button);
}
}
});
mp = MediaPlayer.create(getApplicationContext(), path[flag]);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
btnPlay.setBackgroundResource(R.drawable.play_button);
}
});

最佳答案

您应该重写该方法

mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
@Override
public void onCompletion(MediaPlayer mp) {
btnPlay.setBackgroundResource(R.drawable.play_button);
}
});

关于java - setOnCompletionListener 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36664621/

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