예제 #1
0
파일: VideoView.java 프로젝트: avenwu/vplus
 public void surfaceCreated(SurfaceHolder holder) {
   mSurfaceHolder = holder;
   if (mMediaPlayer != null
       && mCurrentState == STATE_SUSPEND
       && mTargetState == STATE_RESUME) {
     mMediaPlayer.setDisplay(mSurfaceHolder);
     resume();
   } else {
     openVideo();
   }
 }
예제 #2
0
파일: VideoView.java 프로젝트: avenwu/vplus
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) return;

    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    mContext.sendBroadcast(i);

    release(false);
    try {
      mDuration = -1;
      mCurrentBufferPercentage = 0;
      // mMediaPlayer = new AndroidMediaPlayer();
      IjkMediaPlayer ijkMediaPlayer = null;
      if (mUri != null) {
        ijkMediaPlayer = new IjkMediaPlayer();
        ijkMediaPlayer.setAvOption(AvFormatOption_HttpDetectRangeSupport.Disable);
        ijkMediaPlayer.setOverlayFormat(AvFourCC.SDL_FCC_RV32);

        ijkMediaPlayer.setAvCodecOption("skip_loop_filter", "48");
        ijkMediaPlayer.setFrameDrop(12);
        if (mUserAgent != null) {
          ijkMediaPlayer.setAvFormatOption("user_agent", mUserAgent);
        }
      }
      mMediaPlayer = ijkMediaPlayer;
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mMediaPlayer.setOnInfoListener(mInfoListener);
      mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
      if (mUri != null) mMediaPlayer.setDataSource(mUri.toString());
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      DebugLog.e(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, IMediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      DebugLog.e(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, IMediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    }
  }
예제 #3
0
파일: VideoView.java 프로젝트: avenwu/vplus
        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
          mSurfaceHolder = holder;
          if (mMediaPlayer != null) {
            mMediaPlayer.setDisplay(mSurfaceHolder);
          }

          mSurfaceWidth = w;
          mSurfaceHeight = h;
          boolean isValidState = (mTargetState == STATE_PLAYING);
          boolean hasValidSize = (mVideoWidth == w && mVideoHeight == h);
          if (mMediaPlayer != null && isValidState && hasValidSize) {
            if (mSeekWhenPrepared != 0) seekTo(mSeekWhenPrepared);
            start();
            if (mMediaController != null) {
              if (mMediaController.isShowing()) mMediaController.hide();
              mMediaController.show();
            }
          }
        }