android使用mediaPlayer显示视频时,抛出java.lang.IllegalStateException异常
来源:互联网 发布:关于吃的网络用语 编辑:程序博客网 时间:2024/05/18 02:25
使用Mediaplayer播放视频时,自定义了进度条显示进度,一次需要使用run方法来实时监测视频播放的位置,代码如下:Runnable runnable = new Runnable() {
@Override
public void run() {
if (player != null) {
int pos = player.getCurrentPosition();
if (pos > 0) {
int duration = player.getDuration();
int ss = (int) (player.getCurrentPosition() * 100)
/ duration;
progress.setProgress(ss);
video_time.setText(TimerUtils.formatTimes(player
.getCurrentPosition()));
if (pos == duration) {
player.pause();
btn_player
.setBackgroundResource(R.drawable.bt_view_play);
}
} else {
video_time.setText("00:00");
progress.setProgress(0);
}
}
view_handler.postDelayed(runnable, 1000);
}
};
但是在退出该activity时,总是会报错java.lang.IllegalStateException,而位置则是指向 player.getCurrentPosition(),
在onDestroy方法中relese掉了mediaplayer,但是仍会报错;后来发现,当退出该activity时,将其destroy掉了,但是只是释放掉player是不够的,同时还要增加判断
if (player != null) {
player = null;
}
将mediaplayer设置为空,runnable 中的内容就不会在退出activity时继续执行,而引起异常了。
- android使用mediaPlayer显示视频时,抛出java.lang.IllegalStateException异常
- 使用jspsmartupload上传文件抛出的java.lang.IllegalStateException异常
- Android setPixel抛出java.lang.IllegalStateException
- android使用自定义控件 IconTabPageIndicator时抛出java.lang.IllegalStateException的解决办法
- Android异常: java.lang.IllegalStateException
- MediaRecorder录音,start时候,抛出java.lang.IllegalStateException异常
- 【Servlet+Struts2】文件下载时抛出java.lang.IllegalStateException异常的解决方法
- android studio 报 java.lang.IllegalStateException 异常
- java.lang.IllegalStateException 异常
- 异常:java.lang.IllegalStateException
- Android使用MediaPlayer开发时抛IllegalStateException
- Android使用MediaPlayer开发时抛IllegalStateException
- Android使用MediaPlayer开发时抛IllegalStateException
- Android使用MediaPlayer开发时抛IllegalStateException
- 使用ibatis抛出java.lang.IllegalArgumentException实则抛出:NestedSQLException异常
- java.lang.IllegalStateException: getWriter() 异常(Filter时)
- 解决使用MediaPlayer开发时抛IllegalStateException异常的办法
- java.lang.IllegalStateException异常解决办法
- 线程同步工具之CountDownLatch
- String的compareTo()方法
- tableViewCell 的重用机制下 (内容重叠)问题解决
- iframe自适应高度和宽度
- VS中无签名UTF8和带签名UTF8格式
- android使用mediaPlayer显示视频时,抛出java.lang.IllegalStateException异常
- Des前台加密、后台解密Demo
- 在程序中加入声音
- ORA-01720: grant option does not exist for 'xxx.xxxx' (ORA-01720 ‘XXX’ 不存在授权选项)
- 数据结构课程设计-学生信息管理
- linux系统中查找命令grep命令详解
- HTTP POST GET SOAP本质区别详解
- 懒加载,属性和成员变量,局部变量的据别联系
- JAVA各种编码所占用的字节数