在做播放视频的时候,发现videoView不能充满整个屏幕,在布局中设置充满父窗体也不行,最后重写onMeasure解决了问题:
public class FullScreenVideoView extends VideoView {
public FullScreenVideoView(Context context) {
super(context);
}
public FullScreenVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FullScreenVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
setMeasuredDimension(width, height);
}
}
如果视频上有view布局,比如文本,会出现与视频不同步显示的问题,这是因为视频加载是有延迟的,这就会导致view先显示出来,等一会视频才加载出来,实现同步解决办法如下:
让view布局先隐藏,给video_view设置监听,等加载视频准备完成,在显示view即可。
view.setVisibility(View.GONE);
video_view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
view.setVisibility(View.VISIBLE);
}
});
网友评论