我正在制作一个像 MX 播放器这样的视频播放器 android 应用程序。我想做的和 MX 播放器一样。例如:如果用户点击纵横比按钮,它应该将视频大小设置为100%。如果用户再次点击它应该设置的按钮(宽高比或缩放类型为crop。在下一次点击它应该设置为stretch。再次它应该设置为< strong>适合屏幕等
除此按钮外,我还开发了播放器的其他逻辑。我也会处理宽高比按钮上的点击逻辑。
请告诉我需要编写什么代码才能在用户选择按钮时更改视频大小而不是表面 View 大小。
注意:我根本没有使用视频 View 。我正在通过表面支架分配表面 View 媒体播放器。并且默认我的视频全屏播放
最佳答案
经过一番研究,我终于完成了。如果有人正在寻找答案,那么它就在这里等着你。虽然它不是正确的尺寸,但这只是一个例子。 设置的文本不是根据宽度和高度但它只是为了解释 strong> 你的功能
您可以获取屏幕宽度和高度以及+/-您想要的数量>增加或减少宽度和高度任何你想要的。
在您的 Activity 上方,导入之后,您将此写入初始化:
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;
}
}
}
关于android - 使用像 MX 播放器一样的 Surface View 在 Button Click 上更改视频的纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47900142/