public CustVideoView(final Context context, Video video) { super(context); this.context = context; this.setVideo(video); String frame = video.getFrame(); String closesOnEnd = video.getClosesOnEnd(); if (closesOnEnd != null && closesOnEnd.equalsIgnoreCase("true")) { autoClose = true; } fullscreen = video.getFullscreen(); FrameLayout.LayoutParams params; int[] frames = FrameUtil.frame2int(frame); frames = FrameUtil.autoAdjust(frames, context); // 全屏模式 if (fullscreen.equalsIgnoreCase("true")) { act = (Activity) context; Display display = act.getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); params = new FrameLayout.LayoutParams(width, height); params.topMargin = 0; params.leftMargin = 0; setMeasuredDimension(width, height); } else { params = new FrameLayout.LayoutParams(frames[2], frames[3]); params.setMargins(frames[0], frames[1], 0, 0); } setLayoutParams(params); String path = AppConfigUtil.getAppResource(AppConfigUtil.MAGAZINE_ID) + video.getResource(); setVideoPath(path); setVisibility(View.VISIBLE); setOnCompletionListener( new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { MagazineActivity act = (MagazineActivity) context; act.getvControllers().remove(this); if (autoClose) { setVisibility(View.INVISIBLE); showLayers(); } } }); setOnClickListener(this); }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { // 全屏模式 String fullscreen = video.getFullscreen(); if (fullscreen.equalsIgnoreCase("true")) { Display display = act.getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); super.onLayout(changed, left, top, width, height); } else { super.onLayout(changed, left, top, right, bottom); } }