private static void configureVideo(VideoView videoView, int videoWidth, int videoHeight) { // get the display Context context = AnkiDroidApp.getInstance().getApplicationContext(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); // adjust the size of the video so it fits on the screen float videoProportion = (float) videoWidth / (float) videoHeight; Point point = new Point(); display.getSize(point); int screenWidth = point.x; int screenHeight = point.y; float screenProportion = (float) screenWidth / (float) screenHeight; android.view.ViewGroup.LayoutParams lp = videoView.getLayoutParams(); if (videoProportion > screenProportion) { lp.width = screenWidth; lp.height = (int) ((float) screenWidth / videoProportion); } else { lp.width = (int) (videoProportion * (float) screenHeight); lp.height = screenHeight; } videoView.setLayoutParams(lp); }
public class MainActivity extends Activity { private VideoView vv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); vv = (VideoView) findViewById(R.id.videoView); vv.setVideoPath("sdcard/foo/foo.mp4"); vv.start(); } public void goright(View v) { RelativeLayout.LayoutParams ll = (RelativeLayout.LayoutParams) vv .getLayoutParams(); ll.setMargins(ll.leftMargin - 100, ll.topMargin, ll.rightMargin, ll.bottomMargin); vv.setLayoutParams(ll); } public void godown(View v) { RelativeLayout.LayoutParams ll = (RelativeLayout.LayoutParams) vv .getLayoutParams(); ll.setMargins(ll.leftMargin, ll.topMargin - 100, ll.rightMargin, ll.bottomMargin); vv.setLayoutParams(ll); } }
@Override public void onPrepared(MediaPlayer mp) { ViewGroup.LayoutParams lp = mVideoView.getLayoutParams(); int videoWidth = mp.getVideoWidth(); int videoHeight = mp.getVideoHeight(); float videoProportion = (float) videoWidth / (float) videoHeight; int screenWidth = mFlVideo.getWidth(); int screenHeight = mFlVideo.getHeight(); float screenProportion = (float) screenWidth / (float) screenHeight; if (videoProportion > screenProportion) { lp.width = screenWidth; lp.height = (int) ((float) screenWidth / videoProportion); } else { lp.width = (int) (videoProportion * (float) screenHeight); lp.height = screenHeight; } mVideoView.setLayoutParams(lp); Log.e("videoView", "videoWidth:" + videoWidth + ", videoHeight:" + videoHeight); } });
private void onVideoPrepared(@NonNull MediaPlayer mp) { // Adjust the size of the video // so it fits on the screen int videoWidth = mp.getVideoWidth(); int videoHeight = mp.getVideoHeight(); float videoProportion = (float) videoWidth / (float) videoHeight; int screenWidth = mLinearVideo.getWidth(); int screenHeight = mLinearVideo.getHeight(); float screenProportion = (float) screenWidth / (float) screenHeight; ViewGroup.LayoutParams lp = mVideoView.getLayoutParams(); if (videoProportion > screenProportion) { lp.width = screenWidth; lp.height = (int) ((float) screenWidth / videoProportion); } else { lp.width = (int) (videoProportion * (float) screenHeight); lp.height = screenHeight; } mVideoView.setLayoutParams(lp); mPlayView.setVisibility(View.VISIBLE); mDuration = mVideoView.getDuration(); setSeekBarPosition(); setTimeFrames(); setTimeVideo(0); if (mOnHgLVideoListener != null) { mOnHgLVideoListener.onVideoPrepared(); } }
ViewGroup.LayoutParams params; params = vView.getLayoutParams();