Sunday, January 26, 2014

Show the video black edges below the upper edge of the gray set surfaceview size


            
Develop a player, when playing video, you need to press the original proportions of the video settings for video proportions, I RelativeLayout Chinese surfaceview controls, layout settings resolution of 1280x720, surfaceview set in code.

android: layout_width = "1280px"
android: layout_height = "720px"
android: layout_marginBottom = "60px"
android: background = "@ drawable/bg1"
android: orientation = "vertical">

android: id = "@ + id / playLinearLayout"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: gravity = "center"
android: orientation = "vertical">

android: id = "@ + id / surface"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: layout_gravity = "center" />



Calculating the ratio of the video to be set
int displayWith = playLinearLayout.getWidth () ;/ / get the width of the layout of the 1280
int displayHeight = playLinearLayout.getHeight () ;/ / get the height of 720
layout
mVideoWidth = mMediaPlayer.getVideoWidth () ;/ / video width 640
Height 272
mVideoHeight = mMediaPlayer.getVideoHeight () ;/ / video
if (mVideoWidth! = 0 && mVideoHeight! = 0) {
/ * Set the video width and height * /
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams (displayWith, displayHeight);
/ / To re-adjust the height of the video display
if (mVideoWidth * displayHeight> displayWith * mVideoHeight) {
params.height = displayWith * mVideoHeight / mVideoWidth;
/ / Video width to re-adjust
else if (mVideoWidth * displayHeight params.width = displayHeight * mVideoWidth / mVideoHeight;
}
else {
params.width = displayWith;
params.height = displayHeight;
}
m_SurfaceView.setLayoutParams (params) ;/ / set surfaceview size is 1280x544
amplified
m_SurfaceHolder.setFixedSize (params.width, params.height);
/ * Start playing * /
mediaPlayerPlay ();

After the operation, the size of the video display is correct, but the video is black top edge, bottom edge is gray, gray side is how it appears? Please Gangster help solve.

My original design intent is to follow the normal video scaling to avoid full screen, the screen tensile deformation.

Reply:
I tried it, your problem is because you layout the width and height in pixels wrote dead, if not dead, then when you write the horizontal screen display is not right, do not know the landlord later resolved No, I have encountered this question

No comments:

Post a Comment