/**
   * set date source
   *
   * @param path
   */
  public void setDataSource(String path)
      throws IOException, IllegalArgumentException, IllegalStateException {

    if (mPlayStatus != VideoConst.PLAY_STATUS_END) {
      MmpTool.LOG_ERROR("Video is playing,can't set setDataSource");
      sendMsg(VideoConst.MSG_IS_PLAYING);
    }

    isEnd = false;

    try {
      mmediaplayer.setDataSource(path);
    } catch (IOException e) {
      e.printStackTrace();
      throw new IOException();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      throw new IllegalArgumentException(e);
    } catch (IllegalStateException e) {
      e.printStackTrace();
      throw new IllegalStateException(e);
    }

    mPlayStatus = VideoConst.PLAY_STATUS_INITED;

    MmpTool.LOG_DBG("setDataSource finish!");
  }
 /** pause */
 public void pause() throws IllegalStateException {
   if (mmediaplayer != null) {
     if (mPlayStatus == VideoConst.PLAY_STATUS_STARTED) {
       try {
         mmediaplayer.pause();
       } catch (IllegalStateException e) {
         e.printStackTrace();
         sendMsg(VideoConst.MSG_INVALID_STATE);
         throw new IllegalStateException(e);
       }
       mPlayStatus = VideoConst.PLAY_STATUS_PAUSED;
       MmpTool.LOG_DBG("pause!");
     } else {
       try {
         mmediaplayer.start();
       } catch (IllegalStateException e) {
         e.printStackTrace();
         sendMsg(VideoConst.MSG_INVALID_STATE);
         throw new IllegalStateException(e);
       }
       mPlayStatus = VideoConst.PLAY_STATUS_STARTED;
       MmpTool.LOG_DBG("play!");
     }
   }
 }
  /** manual preview */
  public void manualPrev() throws IllegalStateException {

    if (mmediaplayer != null) {
      if (mplayerMode == VideoConst.PLAYER_MODE_HTTP) {
        throw new IllegalStateException("Can't do Prev!!!");
      }

      if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON
          || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) {
        if (videopl.getCurrentIndex(Const.FILTER_VIDEO) == 0) {
          throw new IllegalStateException("head of PlayList!!!");
        }
      }
      saveProgress(getProgress());
      if (mPlayStatus != VideoConst.PLAY_STATUS_STOPPED) {
        try {
          mmediaplayer.stop();
        } catch (IllegalStateException e) {
          e.printStackTrace();
          throw new IllegalStateException(e);
        }
        mPlayStatus = VideoConst.PLAY_STATUS_STOPPED;
      }

      mcurPath = videopl.getNext(Const.FILTER_VIDEO, Const.MANUALPRE);

      if (mcurPath == null) {
        MmpTool.LOG_DBG("End of PlayList!");
        stop();
      }

      MmpTool.LOG_DBG(mcurPath);

      mmediaplayer.reset();

      mPlayStatus = VideoConst.PLAY_STATUS_END;

      try {
        setDataSource(mcurPath);
      } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IllegalStateException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }

      try {
        play();
      } catch (IllegalStateException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }
    }
  }
        public void onCompletion(MediaPlayer arg0) {
          // TODO Auto-generated method stub
          MmpTool.LOG_DBG("play compeletion!");

          if (mmediaplayer != null) {

            saveProgress(0);
            if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON
                || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) {
              if (videopl.getCurrentIndex(Const.FILTER_VIDEO)
                  >= ((videopl.getFileNum(Const.FILTER_VIDEO) - 1))) {
                try {
                  isEnd = true;
                  mmediaplayer.stop();
                  mPlayStatus = VideoConst.PLAY_STATUS_END;
                  throw new Exception("End of PlayList!!!");
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            }

            try {
              autoNext();
            } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            if (mOnPBCompleteListener != null) {
              mOnPBCompleteListener.onComplete(pb);
            }
          }
        }
 /** reset */
 public void reset() {
   if (mmediaplayer != null) {
     mmediaplayer.reset();
   }
   mPlayStatus = VideoConst.PLAY_STATUS_UNKNOW;
   MmpTool.LOG_DBG("reset!");
 }
 /** release */
 public void onRelease() {
   mOnPBPreparedListener = null;
   mOnPBCompleteListener = null;
   mOnPBMsgListener = null;
   mPlayStatus = VideoConst.PLAY_STATUS_END;
   videoMsgHandler.removeCallbacksAndMessages(null);
   if (previewMode == false) {
     mmediaplayer.release();
   }
   MmpTool.LOG_DBG("release!");
 }
  /** play */
  public void play() throws IllegalStateException {

    if (mmediaplayer != null) {
      if (mPlayStatus == VideoConst.PLAY_STATUS_PAUSED) {
        try {
          mmediaplayer.start();
        } catch (IllegalStateException e) {
          e.printStackTrace();
          sendMsg(VideoConst.MSG_INVALID_STATE);
          throw new IllegalStateException(e);
        }

        mPlayStatus = VideoConst.PLAY_STATUS_STARTED;

        MmpTool.LOG_DBG("Pause to Play!");

      } else if (mPlayStatus == VideoConst.PLAY_STATUS_STARTED
          || mPlayStatus == VideoConst.PLAY_STATUS_PREPARED) {
        MmpTool.LOG_DBG("Has played or prepared!");
        return;
      } else if (mPlayStatus == VideoConst.PLAY_STATUS_INITED) {
        try {
          mmediaplayer.prepareAsync();
        } catch (IllegalStateException e) {
          e.printStackTrace();
          sendMsg(VideoConst.MSG_INVALID_STATE);
          throw new IllegalStateException(e);
        }
        mPlayStatus = VideoConst.PLAY_STATUS_PREPARED;
      } else {
        MmpTool.LOG_ERROR("Please setDataSource firstly!");
        sendMsg(VideoConst.MSG_SOURCE_NOT_PREPARED);
      }
    } else {
      MmpTool.LOG_ERROR("The player is null!");
      sendMsg(VideoConst.MSG_PLAYER_NOT_PREPARED);
    }
  }
  /** seek */
  public void seek(int msec) throws IllegalStateException {
    if (mmediaplayer != null) {
      try {
        if (msec < getDuration()) {
          MmpTool.LOG_DBG("start seek!");

          mmediaplayer.seekTo(msec);
        }
      } catch (IllegalStateException e) {
        e.printStackTrace();
        sendMsg(VideoConst.MSG_INVALID_STATE);
        throw new IllegalStateException(e);
      }
    }
  }
  private void saveProgress(int progress) {
    if (previewMode == true) {
      return;
    } else {
      vidman = VideoManager.getInstance();
      String path = videopl.getCurrentPath(Const.FILTER_VIDEO);

      String info = "progress = " + Integer.toString(progress);
      MmpTool.LOG_DBG(info);

      if (progress > 0 && progress < getDuration()) {
        vidman.getFileInfo().saveProgress(path, progress);
      } else {
        vidman.getFileInfo().saveProgress(path, 0);
      }
    }
  }
  private void autoNext() {

    if (mmediaplayer != null) {

      if (mplayerMode == VideoConst.PLAYER_MODE_HTTP) {
        MmpTool.LOG_ERROR("This player mode can't do next!");
        throw new IllegalStateException("Can't do Next!!!");
      }

      if (mPlayStatus != VideoConst.PLAY_STATUS_STOPPED) {
        mmediaplayer.stop();
        mPlayStatus = VideoConst.PLAY_STATUS_STOPPED;
      }

      mcurPath = videopl.getNext(Const.FILTER_VIDEO, Const.AUTOPLAY);

      mmediaplayer.reset();

      mPlayStatus = VideoConst.PLAY_STATUS_END;

      try {
        setDataSource(mcurPath);
      } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IllegalStateException e) {
        e.printStackTrace();
      }

      try {
        play();
      } catch (IllegalStateException e) {
        e.printStackTrace();
      }
    }
  }
  /** stop */
  public void stop() throws IllegalStateException {
    if (mmediaplayer != null) {
      try {
        isEnd = true;
        saveProgress(getProgress());
        if (mPlayStatus != VideoConst.PLAY_STATUS_STOPPED) {
          mmediaplayer.stop();
          mPlayStatus = VideoConst.PLAY_STATUS_STOPPED;
        }

        mPlayStatus = VideoConst.PLAY_STATUS_END;
      } catch (IllegalStateException e) {
        e.printStackTrace();
        sendMsg(VideoConst.MSG_INVALID_STATE);
        throw new IllegalStateException(e);
      }

      if (mOnPBCompleteListener != null) {
        mOnPBCompleteListener.onComplete(pb);
      }

      MmpTool.LOG_DBG("stop!");
    }
  }
 /** surface destroyed */
 public void surfaceDestroyed(SurfaceHolder holder) {
   // TODO Auto-generated method stub
   MmpTool.LOG_DBG("Surface Destroyed");
 }
 /** surface changed */
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   // TODO Auto-generated method stub
   MmpTool.LOG_DBG("Surface Changed");
 }
 public boolean onError(MediaPlayer mp, int what, int extra) {
   // TODO Auto-generated method stub
   MmpTool.LOG_ERROR("error happened!");
   mmediaplayer.reset();
   return true;
 }