コード例 #1
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 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);
 }
コード例 #2
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
        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();
          }
        }
コード例 #3
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
        public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
          Log.d("Error: %d, %d", framework_err, impl_err);
          mCurrentState = STATE_ERROR;
          mTargetState = STATE_ERROR;
          if (mMediaController != null) mMediaController.hide();

          if (mOnErrorListener != null) {
            if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err)) return true;
          }

          if (getWindowToken() != null) {
            int message =
                framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
                    ? R.string.VideoView_error_text_invalid_progressive_playback
                    : R.string.VideoView_error_text_unknown;

            new AlertDialog.Builder(mContext)
                .setTitle(R.string.VideoView_error_title)
                .setMessage(message)
                .setPositiveButton(
                    R.string.VideoView_error_button,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        if (mOnCompletionListener != null)
                          mOnCompletionListener.onCompletion(mMediaPlayer);
                      }
                    })
                .setCancelable(false)
                .show();
          }
          return true;
        }
コード例 #4
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 public void suspend() {
   if (isInPlaybackState()) {
     release(false);
     mCurrentState = STATE_SUSPEND_UNSUPPORTED;
     Log.d("Unable to suspend video. Release MediaPlayer.");
   }
 }
コード例 #5
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 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);
 }
コード例 #6
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
        @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
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null || !Vitamio.isInitialized(mContext)) 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 MediaPlayer(mContext);
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mMediaPlayer.setOnInfoListener(mInfoListener);
      mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
      mMediaPlayer.setOnTimedTextListener(mTimedTextListener);
      mMediaPlayer.setDataSource(mContext, mUri);
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      Log.e("Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      Log.e("Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    }
  }
コード例 #8
0
ファイル: StringUtils.java プロジェクト: rptgba/ZI
 public static int convertToInt(String str) throws NumberFormatException {
   int s, e;
   for (s = 0; s < str.length(); s++) if (Character.isDigit(str.charAt(s))) break;
   for (e = str.length(); e > 0; e--) if (Character.isDigit(str.charAt(e - 1))) break;
   if (e > s) {
     try {
       return Integer.parseInt(str.substring(s, e));
     } catch (NumberFormatException ex) {
       Log.e("convertToInt", ex);
       throw new NumberFormatException();
     }
   } else {
     throw new NumberFormatException();
   }
 }
コード例 #9
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 /**
  * 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;
   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;
 }
コード例 #10
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 @Override
 public void onTimedText(String text) {
   Log.i("onSubtitleUpdate: %s", text);
   if (mOnTimedTextListener != null) mOnTimedTextListener.onTimedText(text);
 }
コード例 #11
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 @Override
 public void onTimedTextUpdate(byte[] pixels, int width, int height) {
   Log.i("onSubtitleUpdate: bitmap subtitle, %dx%d", width, height);
   if (mOnTimedTextListener != null)
     mOnTimedTextListener.onTimedTextUpdate(pixels, width, height);
 }
コード例 #12
0
ファイル: VideoView.java プロジェクト: ColbyTang/BiLiBiLi
 @Override
 public void onSeekComplete(MediaPlayer mp) {
   Log.d("onSeekComplete");
   if (mOnSeekCompleteListener != null) mOnSeekCompleteListener.onSeekComplete(mp);
 }