Skip to content

Commit

Permalink
修改了全屏拆建的支持 (2017-04-27)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Apr 27, 2017
1 parent cc466af commit 5a5f190
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_detail_player);
ButterKnife.bind(this);

String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
//String url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
//String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
String url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
//String url = "http://vr.tudou.com/v2proxy/v?sid=95001&id=496378919&st=3&pw=";
//String url = "http://pl-ali.youku.com/playlist/m3u8?type=mp4&ts=1490185963&keyframe=0&vid=XMjYxOTQ1Mzg2MA==&ep=ciadGkiFU8cF4SvajD8bYyuwJiYHXJZ3rHbN%2FrYDAcZuH%2BrC6DPcqJ21TPs%3D&sid=04901859548541247bba8&token=0524&ctype=12&ev=1&oip=976319194";
//String url = "http://hls.ciguang.tv/hdtv/video.m3u8";
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/sample_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
android:layout_height="match_parent"
android:background="@android:color/black">

<RelativeLayout
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

</RelativeLayout>
</FrameLayout>

<com.shuyu.gsyvideoplayer.GSYImageCover
android:id="@+id/cover"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class GSYTextureView extends TextureView {

private int sizeH;

private boolean fullView;

private int originW, originH;

public GSYTextureView(Context context) {
super(context);
}
Expand All @@ -38,6 +42,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthS = getDefaultSize(videoWidth, widthMeasureSpec);
int heightS = getDefaultSize(videoHeight, heightMeasureSpec);

if (originW == 0 || originH == 0) {
originW = widthS;
originH = heightS;
}

///Debuger.printfError("******** video size " + getRotation() + " " + videoHeight + " *****1 " + videoWidth);
//Debuger.printfError("******** widget size " + widthS + " *****2 " + heightS);
if (videoWidth > 0 && videoHeight > 0) {
Expand Down Expand Up @@ -85,8 +94,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}

//Debuger.printfError("******** rotate before " + width + " *****3 " + height);

if (getRotation() != 0 && getRotation() % 90 == 0 && Math.abs(getRotation()) != 180) {
boolean rotate = (getRotation() != 0 && getRotation() % 90 == 0 && Math.abs(getRotation()) != 180);
if (rotate) {
if (widthS < heightS) {
if (width > height) {
width = (int) (width * (float) widthS / height);
Expand Down Expand Up @@ -145,6 +154,47 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

//上面会调整一变全屏,这里如果要全屏裁减,就整另外一边
if (true) {
if (rotate && getRotation() != 0) {
if (width > height) {
if (height < originW) {
width = (int) (width * ((float) originW / height));
height = originW;
} else if (width < originH) {
height = (int) (height * ((float) originH / width));
width = originH;
}
} else {
if (width < originH) {
height = (int) (height * ((float) originH / width));
width = originH;
} else if (height < originW) {
width = (int) (width * ((float) originW / height));
height = originW;
}
}
} else {
if (height > width) {
if (width < widthS) {
height = (int) (height * ((float) widthS / width));
width = widthS;
} else {
width = (int) (width * ((float) heightS / height));
height = heightS;
}
} else {
if (height < heightS) {
width = (int) (width * ((float) heightS / height));
height = heightS;
} else {
height = (int) (height * ((float) widthS / width));
width = widthS;
}
}
}
}

sizeH = height;

sizeW = width;
Expand All @@ -159,4 +209,12 @@ public int getSizeH() {
public int getSizeW() {
return sizeW;
}

public boolean isFullView() {
return fullView;
}

public void setFullView(boolean fullView) {
this.fullView = fullView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.TextureView;
Expand All @@ -16,6 +17,7 @@
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
Expand Down Expand Up @@ -174,7 +176,7 @@ protected void init(Context context) {
mCurrentTimeTextView = (TextView) findViewById(R.id.current);
mTotalTimeTextView = (TextView) findViewById(R.id.total);
mBottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
mTextureViewContainer = (RelativeLayout) findViewById(R.id.surface_container);
mTextureViewContainer = (ViewGroup) findViewById(R.id.surface_container);
mTopContainer = (ViewGroup) findViewById(R.id.layout_top);
if (isInEditMode())
return;
Expand Down Expand Up @@ -480,9 +482,15 @@ protected void addTextureView() {
mTextureView.setSurfaceTextureListener(this);
mTextureView.setRotation(mRotate);

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mTextureViewContainer.addView(mTextureView, layoutParams);
if(mTextureViewContainer instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mTextureViewContainer.addView(mTextureView, layoutParams);
} else if(mTextureViewContainer instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.CENTER;
mTextureViewContainer.addView(mTextureView, layoutParams);
}
}

/**
Expand Down

0 comments on commit 5a5f190

Please sign in to comment.