화면에 꽉차게 하거나 크기를 다르게 적용하고 싶으면 VideoView 가 갖고 있는 MediaPlayer 의 onVideoSizeChanged 핸들러를 변경해 주어야 한다.
화면에 꽉차게 표시 (fill_parent)
... VideoView videoView; ... private OnVideoSizeChangedListener onVideoSizeChangedListener = new OnVideoSizeChangedListener() { public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); videoView.setLayoutParams(lp); } }; ... private OnPreparedListener onPrepared = new OnPreparedListener() { public void onPrepared(MediaPlayer mp) { mp.setOnVideoSizeChangedListener(onVideoSizeChangedListener); LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); videoView.setLayoutParams(lp); } }; ... videoView.setOnPreparedListener(onPrepared);
요약)
VideoView 의 onPreparedListener 에서 전달되는 MediaPlayer 에 onVideoSizeChangedListener 를 등록시킨다.
VideoView 의 setLayoutParams 함수를 이용하여 크기를 변경한다.
주의) setLayoutParams 사용시 주의할 사항이 있다. 참조
댓글 없음:
댓글 쓰기