我有个问题。即使活动停止,我的媒体播放器也不会停止。所以我很困惑为什么媒体播放器不会停止。媒体播放器立即播放,直到 mp3 播放完毕。这是我的代码
public class Isi_TakbiratulIhram extends Activity{
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.isitakbiratulihram);
ImageButton iftitah1=(ImageButton) findViewById (R.id.takbiratulihram1);
iftitah1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
go();
}
public void go(){
if(mp != null ){
mp.stop();
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.seekTo(0);
mp = null;
}
else {
mp=MediaPlayer.create(Isi_TakbiratulIhram.this, R.raw.iftitah1);
mp.start();
}
}});
感谢帮助