使用像 MX 播放器一样的 Surface View 在 Button Click 上更改视频的纵横比
Changing Aspect Ratio of the video on Button Click using Surface View like MX player
我正在制作类似 MX 播放器的视频播放器 android 应用程序。我想做的就像在 MX player.For example:If 中一样用户点击 宽高比 按钮它应该将视频大小设置为 100%。如果用户再次单击它应该设置的按钮(纵横比或缩放类型为 crop。在下次单击时它应该设置为 stretch。它应该设置为适合屏幕等
除了这个按钮,我已经开发了播放器的其他逻辑。我也会处理宽高比按钮上的点击逻辑。
请告诉我我需要编写什么代码来更改视频大小而不是表面视图大小 当用户选择按钮时。
注意:我根本没有使用视频视图。我正在通过表面支架分配表面视图媒体播放器。 默认我的视频全屏播放
经过一番研究,我终于完成了。如果有人正在寻找答案,那么它就在这里等着你。虽然 不是 正确的尺寸 但它只是一个例子。根据 width 和 height[=44=,set Text not ] 但它 只是为了向您解释 功能
你可以获取屏幕宽度和高度和+ /- 在 width 和 身高随便你。
在你的 activity 之上,在 imports 之后,你将其写入 initialize:
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;
}
}
}
我正在制作类似 MX 播放器的视频播放器 android 应用程序。我想做的就像在 MX player.For example:If 中一样用户点击 宽高比 按钮它应该将视频大小设置为 100%。如果用户再次单击它应该设置的按钮(纵横比或缩放类型为 crop。在下次单击时它应该设置为 stretch。它应该设置为适合屏幕等
除了这个按钮,我已经开发了播放器的其他逻辑。我也会处理宽高比按钮上的点击逻辑。
请告诉我我需要编写什么代码来更改视频大小而不是表面视图大小 当用户选择按钮时。
注意:我根本没有使用视频视图。我正在通过表面支架分配表面视图媒体播放器。 默认我的视频全屏播放
经过一番研究,我终于完成了。如果有人正在寻找答案,那么它就在这里等着你。虽然 不是 正确的尺寸 但它只是一个例子。根据 width 和 height[=44=,set Text not ] 但它 只是为了向您解释 功能
你可以获取屏幕宽度和高度和+ /- 在 width 和 身高随便你。
在你的 activity 之上,在 imports 之后,你将其写入 initialize:
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;
}
}
}