<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Cyh的博客

    Email:kissyan4916@163.com
    posts - 26, comments - 19, trackbacks - 0, articles - 220

    Android游戲開發之旅(九)VideoView類剖析

    Posted on 2010-12-03 10:24 啥都寫點 閱讀(390) 評論(0)  編輯  收藏 所屬分類: Android

    有關SurfaceView 相關的內容今天Android123繼續延用系統 的示例類VideoView來讓大家深入了解Android平臺 的圖形繪制基礎類的實現原理。大家可能會發現VideoView類的控制方面無法改變,我們可以通過重構VideoView類來實現更個性化的播放 器

    view plaincopy to clipboardprint?
    public class VideoView extends SurfaceView implements MediaPlayerControl {  
      private String TAG = "VideoView";  
      // settable by the client  
      private Uri        mUri;  
      private int        mDuration;  
      // all possible internal states  
      private static final int STATE_ERROR              = -1;  
      private static final int STATE_IDLE              = 0;  
      private static final int STATE_PREPARING          = 1;  
      private static final int STATE_PREPARED          = 2;  
      private static final int STATE_PLAYING            = 3;  
      private static final int STATE_PAUSED            = 4;  
      private static final int STATE_PLAYBACK_COMPLETED = 5;  
      // mCurrentState is a VideoView object's current state.  
      // mTargetState is the state that a method caller intends to reach.  
      // For instance, regardless the VideoView object's current state,  
      // calling pause() intends to bring the object to a target state  
      // of STATE_PAUSED.  
      private int mCurrentState = STATE_IDLE;  
      private int mTargetState  = STATE_IDLE;  
      // All the stuff we need for playing and showing a video  
      private SurfaceHolder mSurfaceHolder = null;  
      private MediaPlayer mMediaPlayer = null;  
      private int        mVideoWidth;  
      private int        mVideoHeight;  
      private int        mSurfaceWidth;  
      private int        mSurfaceHeight;  
      private MediaController mMediaController;  
      private OnCompletionListener mOnCompletionListener;  
      private MediaPlayer.OnPreparedListener mOnPreparedListener;  
      private int        mCurrentBufferPercentage;  
      private OnErrorListener mOnErrorListener;  
      private int        mSeekWhenPrepared;  // recording the seek position while preparing  
      private boolean    mCanPause;  
      private boolean    mCanSeekBack;  
      private boolean    mCanSeekForward;  
      public VideoView(Context context) {  
          super(context);  
          initVideoView();  
      }  
     
      public VideoView(Context context, AttributeSet attrs) {  
          this(context, attrs, 0);  
          initVideoView();  
      }  
     
      public VideoView(Context context, AttributeSet attrs, int defStyle) {  
          super(context, attrs, defStyle);  
          initVideoView();  
      }  
      @Override 
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
          //Log.i("@@@@", "onMeasure");  
          int width = getDefaultSize(mVideoWidth, widthMeasureSpec);  
          int height = getDefaultSize(mVideoHeight, heightMeasureSpec);  
          if (mVideoWidth > 0 && mVideoHeight > 0) {  
              if ( mVideoWidth * height  > width * mVideoHeight ) {  
                  //Log.i("@@@", "image too tall, correcting");  
                  height = width * mVideoHeight / mVideoWidth;  
              } else if ( mVideoWidth * height  < width * mVideoHeight ) {  
                  //Log.i("@@@", "image too wide, correcting");  
                  width = height * mVideoWidth / mVideoHeight;  
              } else {  
                  //Log.i("@@@", "aspect ratio is correct: " +  
                          //width+"/"+height+"="+  
                          //mVideoWidth+"/"+mVideoHeight);  
              }  
          }  
          //Log.i("@@@@@@@@@@", "setting size: " + width + 'x' + height);  
          setMeasuredDimension(width, height);  
      }  
     
      public int resolveAdjustedSize(int desiredSize, int measureSpec) {  
          int result = desiredSize;  
          int specMode = MeasureSpec.getMode(measureSpec);  
          int specSize =  MeasureSpec.getSize(measureSpec);  
          switch (specMode) {  
              case MeasureSpec.UNSPECIFIED:  
                  /* Parent says we can be as big as we want. Just don't be larger 
                  * than max size imposed on ourselves. 
                  */ 
                  result = desiredSize;  
                  break;  
              case MeasureSpec.AT_MOST:  
                  /* Parent says we can be as big as we want, up to specSize. 
                  * Don't be larger than specSize, and don't be larger than 
                  * the max size imposed on ourselves. 
                  */ 
                  result = Math.min(desiredSize, specSize);  
                  break;  
                  
              case MeasureSpec.EXACTLY:  
                  // No choice. Do what we are told.  
                  result = specSize;  
                  break;  
          }  
          return result;  

     

    本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/JavaTiger427/archive/2010/11/25/6034570.aspx



                                                                                                           --    學海無涯
            

    主站蜘蛛池模板: 无码乱人伦一区二区亚洲| 日本免费网站观看| 亚洲精品无码av人在线观看| 免费国产高清毛不卡片基地| 全部免费国产潢色一级| 黄网站色成年片大免费高清| 亚洲国产成人久久精品99| 日韩在线一区二区三区免费视频| 亚洲国产成人久久一区久久| 草久免费在线观看网站| 久久久久一级精品亚洲国产成人综合AV区 | 亚洲砖码砖专无区2023| 成人性生交视频免费观看| 亚洲精品无码中文久久字幕| 国产伦一区二区三区免费| 一级毛片人与动免费观看| 亚洲AV无码一区二区三区系列 | 久久午夜伦鲁片免费无码| 亚洲精品午夜久久久伊人| 国产精品69白浆在线观看免费| 亚洲人成电影网站久久| 亚洲AⅤ视频一区二区三区| 岛国岛国免费V片在线观看 | 2021久久精品免费观看| 久久久久久亚洲av无码蜜芽| 亚洲国产成人久久综合区| 国产永久免费高清在线| 欧洲 亚洲 国产图片综合| 亚洲精品成人久久久| 久久这里只精品国产免费10| 中文字幕亚洲精品无码| 久久精品国产亚洲5555| 免费能直接在线观看黄的视频| 亚洲乱色伦图片区小说| 亚洲日韩精品无码专区网站| 亚洲精品免费在线视频| 亚洲精品动漫免费二区| 亚洲Av无码精品色午夜| 毛色毛片免费观看| a毛片免费播放全部完整| 亚洲欧美国产国产一区二区三区|