Example #1
0
  private void openVideo() {
    if (mUri == null || mSurface == null) {
      return;
    }

    if (mEnableMusicPause) {
      sendMusicPauseRequest();
    }

    release(false);
    try {
      mPlayer = new MediaPlayer();
      mPlayer.setOnPreparedListener(mPreparedListener);
      mPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mPlayer.setOnCompletionListener(mCompletionListener);
      mPlayer.setOnErrorListener(mErrorListener);
      mPlayer.setDataSource(mCtx, mUri);
      mPlayer.setSurface(mSurface);
      mSurface.release();
      mSurface = null;
      mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mPlayer.setParameter(CLEAR_MOTION_KEY, CLEAR_MOTION_DISABLE);
      mPlayer.prepareAsync();
      setCurrentState(STATE_PREPARING);
    } catch (IOException ex) {
      Log.e(TAG, "IOException : " + ex);
      setAllState(STATE_ERROR);
      mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    } catch (IllegalArgumentException ex) {
      Log.e(TAG, "IllegalArgumentException : " + ex);
      setAllState(STATE_ERROR);
      mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    }
  }
Example #2
0
 private boolean notifyErrorListener(MediaPlayer mediaplayer, int frameworkErr, int implErr) {
   if (mOnErrorListener != null) {
     mOnErrorListener.onError(mediaplayer, frameworkErr, implErr);
     return true;
   }
   return false;
 }
 @Override
 public boolean onError(MediaPlayer mp, int what, int extra) {
   Log.d(TAG, "onError()");
   mPreparedQuery = null;
   mPreparingQuery = null;
   return mOnErrorListener.onError(mp, what, extra);
 }
        @Override
        public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
          Logger.e("[VideoView]Error:" + framework_err + "," + impl_err);
          mCurrentState = STATE_ERROR;
          //			mTargetState = STATE_ERROR;
          // FIX,可以考虑出错以后重新开始
          if (mOnErrorListener != null) mOnErrorListener.onError(mp, framework_err, impl_err);

          return true;
        }
 @Override
 public int getCurrentPosition() {
   switch (state) {
     case ERROR:
       error("getCurrentPosition");
       if (onErrorListener != null) {
         onErrorListener.onError(null, 0, 0);
       }
       return 0;
     case IDLE:
       return 0;
     default:
       return (int) (extractor.getSampleTime() / 1000);
   }
 }