示例#1
0
        @Override
        public void onPrepared(MediaPlayer mp) {
          Log.d("onPrepared");
          mCurrentState = STATE_PREPARED;
          mTargetState = STATE_PLAYING;

          if (mOnPreparedListener != null) mOnPreparedListener.onPrepared(mMediaPlayer);
          if (mMediaController != null) mMediaController.setEnabled(true);
          mVideoWidth = mp.getVideoWidth();
          mVideoHeight = mp.getVideoHeight();
          mVideoAspectRatio = mp.getVideoAspectRatio();

          long seekToPosition = mSeekWhenPrepared;

          if (seekToPosition != 0) seekTo(seekToPosition);
          if (mVideoWidth != 0 && mVideoHeight != 0) {
            setVideoLayout(mVideoLayout, mAspectRatio);
            if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
              if (mTargetState == STATE_PLAYING) {
                start();
                if (mMediaController != null) mMediaController.show();
              } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) {
                if (mMediaController != null) mMediaController.show(0);
              }
            }
          } else if (mTargetState == STATE_PLAYING) {
            start();
          }
        }
示例#2
0
 public void suspend() {
   if (isInPlaybackState()) {
     release(false);
     mCurrentState = STATE_SUSPEND_UNSUPPORTED;
     Log.d("Unable to suspend video. Release MediaPlayer.");
   }
 }
示例#3
0
 @Override
 public void onCompletion(MediaPlayer mp) {
   Log.d("onCompletion");
   mCurrentState = STATE_PLAYBACK_COMPLETED;
   mTargetState = STATE_PLAYBACK_COMPLETED;
   if (mMediaController != null) mMediaController.hide();
   if (mOnCompletionListener != null) mOnCompletionListener.onCompletion(mMediaPlayer);
 }
示例#4
0
 @Override
 public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
   Log.d("onVideoSizeChanged: (%dx%d)", width, height);
   mVideoWidth = mp.getVideoWidth();
   mVideoHeight = mp.getVideoHeight();
   mVideoAspectRatio = mp.getVideoAspectRatio();
   if (mVideoWidth != 0 && mVideoHeight != 0) setVideoLayout(mVideoLayout, mAspectRatio);
 }
示例#5
0
 /**
  * Set the display options
  *
  * @param layout
  *     <ul>
  *       <li>{@link #VIDEO_LAYOUT_ORIGIN}
  *       <li>{@link #VIDEO_LAYOUT_SCALE}
  *       <li>{@link #VIDEO_LAYOUT_STRETCH}
  *       <li>{@link #VIDEO_LAYOUT_ZOOM}
  *     </ul>
  *
  * @param aspectRatio video aspect ratio, will audo detect if 0.
  */
 public void setVideoLayout(int layout, float aspectRatio) {
   LayoutParams lp = getLayoutParams();
   DisplayMetrics disp = mContext.getResources().getDisplayMetrics();
   int windowWidth = disp.widthPixels, windowHeight = disp.heightPixels;
   Log.d(
       "VideoView width and height",
       " width ============== " + windowWidth + ", height ============== " + windowHeight);
   float windowRatio = windowWidth / (float) windowHeight;
   float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
   mSurfaceHeight = mVideoHeight;
   mSurfaceWidth = mVideoWidth;
   if (VIDEO_LAYOUT_ORIGIN == layout
       && mSurfaceWidth < windowWidth
       && mSurfaceHeight < windowHeight) {
     lp.width = (int) (mSurfaceHeight * videoRatio);
     lp.height = mSurfaceHeight;
   } else if (layout == VIDEO_LAYOUT_ZOOM) {
     lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
     lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
   } else {
     boolean full = layout == VIDEO_LAYOUT_STRETCH;
     lp.width =
         (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
     lp.height =
         (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
   }
   setLayoutParams(lp);
   getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
   Log.d(
       "VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f",
       mVideoWidth,
       mVideoHeight,
       mVideoAspectRatio,
       mSurfaceWidth,
       mSurfaceHeight,
       lp.width,
       lp.height,
       windowWidth,
       windowHeight,
       windowRatio);
   mVideoLayout = layout;
   mAspectRatio = aspectRatio;
 }
示例#6
0
        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
          Log.d("onInfo: (%d, %d)", what, extra);
          if (mOnInfoListener != null) {
            mOnInfoListener.onInfo(mp, what, extra);
          } else if (mMediaPlayer != null) {
            if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) mMediaPlayer.pause();
            else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) mMediaPlayer.start();
          }

          return true;
        }
示例#7
0
 @Override
 public void onSeekComplete(MediaPlayer mp) {
   Log.d("onSeekComplete");
   if (mOnSeekCompleteListener != null) mOnSeekCompleteListener.onSeekComplete(mp);
 }