Skip to content

Commit

Permalink
增加旋转播放画面的demo (2017-04-13)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Apr 13, 2017
1 parent b918ba9 commit 56ea58a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,22 @@ public void onClick(View v) {
}
});

//旋转播放角度
mChangeRotate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if((mTextureView.getRotation() - mRotate) == 270) {
mTextureView.setRotation(mRotate);
mCoverImageView.setRotation(mRotate);

mTextureView.requestLayout();
mCoverImageView.requestLayout();
} else {
mTextureView.setRotation(mTextureView.getRotation() + 90);
mCoverImageView.setRotation(mCoverImageView.getRotation() + 90);

mTextureView.requestLayout();
mCoverImageView.requestLayout();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.util.AttributeSet;
import android.widget.ImageView;

import com.shuyu.gsyvideoplayer.utils.GSYVideoType;

/**
* Created by shuyu on 2016/12/6.
*/
Expand Down Expand Up @@ -35,7 +37,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthS = getDefaultSize(videoWidth, widthMeasureSpec);
int heightS = getDefaultSize(videoHeight, heightMeasureSpec);


///Debuger.printfError("******** video size " + getRotation() + " " + videoHeight + " *****1 " + videoWidth);
//Debuger.printfError("******** widget size " + widthS + " *****2 " + heightS);
if (videoWidth > 0 && videoHeight > 0) {

int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
Expand Down Expand Up @@ -80,7 +83,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// no size yet, just adopt the given spec sizes
}

if (getRotation() != 0 && getRotation() % 90 == 0) {
//Debuger.printfError("******** rotate before " + width + " *****3 " + height);

if (getRotation() != 0 && getRotation() % 90 == 0 && Math.abs(getRotation()) != 180) {
if (widthS < heightS) {
if (width > height) {
width = (int) (width * (float) widthS / height);
Expand All @@ -99,6 +104,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

//Debuger.printfError("******** real size before " + width + " *****3 " + height);
//如果旋转后的高度大于宽度
if (width > height) {
//如果视频的旋转后,width(高度)大于控件高度,需要压缩下高度
if (heightS < widthS) {
Expand All @@ -120,6 +127,22 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}
}

//Debuger.printfError("******** real size " + width + " *****3 " + height);
//如果设置了比例
if (GSYVideoType.getShowType() == GSYVideoType.SCREEN_TYPE_16_9) {
if (height > width) {
width = height * 9 / 16;
} else {
height = width * 9 / 16;
}
} else if (GSYVideoType.getShowType() == GSYVideoType.SCREEN_TYPE_4_3) {
if (height > width) {
width = height * 3 / 4;
} else {
height = width * 3 / 4;
}
}
setMeasuredDimension(width, height);
}

Expand Down

0 comments on commit 56ea58a

Please sign in to comment.