很多朋友问小编在使用MediaPlayer播放音频时报出 E/MediaPlayerNative: start called in state 1, mPlayer(0x0)问题,该如何处理呢,今天小编给大家带来了Android Studio 视频播放失败 start called in state1 异常问题,需要的朋友可以参考下
在使用MediaPlayer播放音频时报出 E/MediaPlayerNative: start called in state 1, mPlayer(0x0)
@Override
public void onClick(View v){
Bundle b = new Bundle ();
switch(v.getId ()){
case R.id.start: //获取一个Message变量,用来传递点击状态的值
msg = myHandle.obtainMessage (); //把状态的值放在Bundle对象里面
b.putInt(“status”,1);
msg.setData(b);
msg.sendToTarget ();
break;
case R.id.pause:
msg = myHandle.obtainMessage ();
b.putInt("status",2);
msg.setData(b);
msg.sendToTarget ();
break;
case R.id.restart:
msg = myHandle.obtainMessage ();
b.putInt("status",3);
msg.setData(b);
msg.sendToTarget ();
break;
case R.id.stop:
msg = myHandle.obtainMessage ();
b.putInt("status",4);
msg.setData(b);
msg.sendToTarget ();
break;
}
}
class MyHandle extends Handler{
public MyHandle(){
}
public MyHandle(Looper looper){
super(looper);
}
@Override
public void handleMessage(Message msg){
Bundle b = msg.getData ();
int status = b.getInt("status");
if(status == 1){
mMediaPlayer.start ();
}else if (status ==2){
mMediaPlayer.pause();
}else if(status == 3){
mMediaPlayer.seekTo(0);
}else if(status == 4){
mMediaPlayer.stop();
mMediaPlayer.release ();
mMediaPlayer = null;
VideoActivity.this.finish ();
}
总结
到此这篇关于Android Studio 视频播放失败 start called in state1 异常怎么解决的文章就介绍到这了,更多相关android studio 视频播放失败内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!
沃梦达教程
本文标题为:Android Studio 视频播放失败 start called in state1 异常怎么解决
基础教程推荐
猜你喜欢
- IOS获取系统相册中照片的示例代码 2023-01-03
- Android Compose自定义TextField实现自定义的输入框 2023-05-13
- iOS中如何判断当前网络环境是2G/3G/4G/5G/WiFi 2023-06-18
- Flutter进阶之实现动画效果(三) 2022-10-28
- iOS开发 全机型适配解决方法 2023-01-14
- Android实现短信验证码输入框 2023-04-29
- iOS开发使用XML解析网络数据 2022-11-12
- Android开发Compose集成高德地图实例 2023-06-15
- iOS Crash常规跟踪方法及Bugly集成运用详细介绍 2023-01-18
- MVVMLight项目Model View结构及全局视图模型注入器 2023-05-07