亲宝软件园·资讯

展开

android studio 视频播放失败 Android Studio 视频播放失败 start called in state1 异常怎么解决

sherkyhua 人气:0

在使用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 ();
    }

在这里插入图片描述

总结

加载全部内容

相关教程
猜你喜欢
用户评论