当前位置:主页 > 移动开发 > Android代码 >

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

时间:2020-10-17 23:36:07 | 栏目:Android代码 | 点击:

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

在这里插入图片描述

总结

您可能感兴趣的文章:

相关文章