我正在制作像MX播放器一样的视频播放器Android应用程序。我想要做的就像在MX播放器中一样。例如:如果用户点击宽高比按钮,它应该将视频大小设置为100%。如果用户再次单击它应该设置的按钮(宽高比或缩放类型为crop.on下一次单击它应设置为拉伸。再次应将其设置为适合屏幕等。
除了这个按钮,我已经开发了播放器的其他逻辑。我也将处理宽高比按钮上的点击逻辑。
只需告诉我,当用户选择按钮时,我需要编写哪些代码来更改视频大小而不是表面视图大小。
注意:我根本不使用视频视图。我通过表面支架指定媒体播放器的表面视图。默认情况下,我的视频全屏播放
经过一番研究,我最终做到了。如果有人正在寻找答案,那么它就在这里。虽然它不是正确的尺寸,但它是一个例子。设置文本不是根据宽度和高度,但它只是向您解释功能
您可以根据需要获得屏幕宽度和高度以及+/-您想要增加或减少宽度和高度的数量。
在你的活动之上,你在写入此内容后进行初始化:
android.view.ViewGroup.LayoutParams lp;
这段代码将获得设备的宽度和高度。
public void getDeviceWidthAndHeight(){
lp = surfaceView.getLayoutParams();
screenWidth = getWindowManager().getDefaultDisplay().getWidth();
screenHeight = getWindowManager().getDefaultDisplay().getHeight();
}
这段代码将设置您给它的高度和宽度。
@Override
public void onClick(View v) {
int id=v.getId();
if (id==R.id.resize_video){
if (clickCount==0){
getDeviceWidthAndHeight();
lp.width = screenWidth-50;
lp.height = screenHeight-50;
surfaceView.setLayoutParams(lp);
resizeVideo.setText("100%");
clickCount=1;
}
else if (clickCount==1){
getDeviceWidthAndHeight();
lp.width = screenWidth-300;
lp.height = screenHeight-100;
surfaceView.setLayoutParams(lp);
resizeVideo.setText("Full Screen");
clickCount=2;
}
else if(clickCount==2){
getDeviceWidthAndHeight();
lp.width =screenWidth;
lp.height = screenHeight;
surfaceView.setLayoutParams(lp);
resizeVideo.setText("100%");
clickCount=3;
}
else if(clickCount==3){
getDeviceWidthAndHeight();
lp.width =screenWidth;
lp.height = screenHeight-500;
surfaceView.setLayoutParams(lp);
resizeVideo.setText("Fit to Screen");
clickCount=0;
}
}
}