无法启动android MediaPlayer onCompletion [英] Cannot get android MediaPlayer onCompletion to fire
本文介绍了无法启动android MediaPlayer onCompletion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用android MediaPlayer类播放一些声音.
I'm trying to use the android MediaPlayer class to play some sounds.
这是代码
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(context, Uri.parse(soundUrl));
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setLooping(false);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.i(LOGTAG, "onComplete hit");
mp.stop();
mp.release();
}
});
mp.prepare();
mp.start();
此代码在服务中运行,但是由于某种原因,声音可以正常播放,但是放在onCompletion中的任何内容似乎都不会触发.然后,我在logcat中收到一条消息,指出未释放Mediaplayer.我对此感到不知所措.
This code runs in a service, but for some reason the sound plays ok, but anything placed into the onCompletion doesn't seem to fire. I then get a message in the logcat that the mediaplayer wasn't released. I'm at a loss to what I've got wrong with this.
我正在对银河系4.0.4库存光驱进行此测试.
I'm running this testing on a galaxy nexus 4.0.4 stock rom.
我还注意到声音可能会在最后被剪切掉.
I also notice that the sound can get clipped at the end.
推荐答案
这是我的方法:
video.setOnCompletionListener(this);
IntroClip.execute(video);
}
@Override
public void onCompletion(MediaPlayer mp){
Button LoginButton;
Button CreateAccount;
Button RecoverPass;
setContentView(R.layout.loginmenu);
Spin = (ProgressBar)findViewById(R.id.Spinner);
mp.release();
}
这篇关于无法启动android MediaPlayer onCompletion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文