<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



                                                                                                           --    學海無涯
            

    主站蜘蛛池模板: 亚洲国产精品一区二区第一页| 我的小后妈韩剧在线看免费高清版| 精品久久久久久久免费加勒比| 亚洲经典在线中文字幕| 久久午夜夜伦鲁鲁片无码免费| 国产精品亚洲精品日韩已满| 免费无码又爽又刺激一高潮| 亚洲色大成网站WWW久久九九| 久久不见久久见免费影院www日本| 亚洲精品国产自在久久| 无遮挡免费一区二区三区| 免费欧洲毛片A级视频无风险| 精品韩国亚洲av无码不卡区| 亚洲 小说区 图片区 都市| 久久成人免费大片| 亚洲短视频男人的影院| 麻豆高清免费国产一区| 亚洲娇小性xxxx色| 日本免费v片一二三区| 亚洲精品自在在线观看| 久久青草免费91线频观看不卡 | 免费无码av片在线观看| 亚洲AV日韩精品久久久久| 4399影视免费观看高清直播| 亚洲av成人综合网| 国产午夜免费福利红片| 国产福利在线观看永久免费| 久久青青草原亚洲AV无码麻豆| 未满十八18禁止免费无码网站 | 国产精品久久免费| 亚洲成av人片在线天堂无| 男人的天堂亚洲一区二区三区 | 另类免费视频一区二区在线观看| 亚洲国产精品一区| 成人毛片免费视频| 国产区在线免费观看| 亚洲AV无码专区亚洲AV伊甸园| 1000部夫妻午夜免费| 亚洲A∨精品一区二区三区下载| 国产亚洲精品资在线| 国产香蕉免费精品视频|