如何阻止媒体播放器不当,机器人 [英] How to stop media player properly , android
本文介绍了如何阻止媒体播放器不当,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我建立了点击这首歌,我能够发挥利用MedaiPlayer歌曲的歌曲列表。而如果用户点击另一首歌曲那么我停止媒体播放器,并重新开始播放一首歌曲播放。但我正在逐渐IllegalStateException异常复位()。这里是code,其中我收到异常。如何阻止一名球员是否正确?也就是为什么我会收到此异常。如何避免呢?
公共无效stopPlayer(){
尝试 {
如果(玩家!= NULL){
// Log.e(试图阻止,播放器);
player.stop();
player.release();
player.reset(); //使IllegalStateException异常
球员= NULL;
}
}赶上(例外五){
球员= NULL;
playerStatus = FALSE;
e.printStackTrace();
}
}
解决方案
试试这个:
player.reset();
player.release();
和也看看媒体播放器状态图。
I have created a list of songs on click on the song i am able to play the song using MedaiPlayer. While one song is playing if the user clicks another song then i am stopping the media player and starting the player again. But I am getting illegalstateexception in reset(). Here is the code where I am getting the exception. How to stop a player properly? also why am i getting this exception. How to avoid it?
public void stopPlayer() {
try {
if (player != null) {
// Log.e("Trying to Stop "," Player ");
player.stop();
player.release();
player.reset();// causes IllegalstateException
player = null;
}
} catch (Exception e) {
player = null;
playerStatus = false;
e.printStackTrace();
}
}
解决方案
try this :
player.reset();
player.release();
and also have a look at media player state diagram.
这篇关于如何阻止媒体播放器不当,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文