提交 08fc2252 编写于 作者: G guoshuyu

调整部分代码 (2017-10-26)

上级 934428fb
......@@ -19,77 +19,77 @@
android:id="@+id/open_btn"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Open Video" />
android:text="打开Video" />
<Button
android:id="@+id/open_control"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Control" />
android:text="带控制DEMO" />
<Button
android:id="@+id/open_btn_empty"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="NO UI" />
android:text="无UI界面" />
<Button
android:id="@+id/open_filter"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Filter" />
android:text="滤镜" />
<Button
android:id="@+id/open_btn_pick"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Switch" />
android:text="无缝切换" />
<Button
android:id="@+id/list_btn"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="List Video" />
android:text="List列表" />
<Button
android:id="@+id/list_btn_2"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="List Video2" />
android:text="List列表2(弃)" />
<Button
android:id="@+id/recycler"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="recycler" />
android:text="recycler列表" />
<Button
android:id="@+id/recycler_2"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="recycler 2" />
android:text="recycler列表2(弃)" />
<Button
android:id="@+id/list_detail"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Detail Video" />
android:text="Detail模式" />
<Button
android:id="@+id/list_detail_list"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Detail List" />
android:text="Detail列表模式" />
<Button
......@@ -97,7 +97,7 @@
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="web detail" />
android:text="Web detail模式" />
<Button
......@@ -105,28 +105,28 @@
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Danmaku Video" />
android:text="弹幕demo" />
<Button
android:id="@+id/fragment_video"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Fragment" />
android:text="Fragment下使用" />
<Button
android:id="@+id/more_type"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="More Type" />
android:text="多类型模式" />
<Button
android:id="@+id/input_type"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Input Type" />
android:text="输入url" />
<Button
android:id="@+id/clear_cache"
......
......@@ -52,15 +52,16 @@ public class GSYRenderView {
}
public void invalidate() {
mShowView.invalidate();
if (mShowView != null)
mShowView.invalidate();
}
public int getWidth() {
return mShowView.getWidth();
return (mShowView != null) ? mShowView.getWidth() : 0;
}
public int getHeight() {
return mShowView.getHeight();
return (mShowView != null) ? mShowView.getHeight() : 0;
}
public View getShowView() {
......@@ -206,17 +207,7 @@ public class GSYRenderView {
mShowView = gsyTextureView;
int params = getTextureParams();
if (textureViewContainer instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(params, params);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
textureViewContainer.addView(gsyTextureView, layoutParams);
} else if (textureViewContainer instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(params, params);
layoutParams.gravity = Gravity.CENTER;
textureViewContainer.addView(gsyTextureView, layoutParams);
}
addToParent(textureViewContainer, gsyTextureView);
}
/**
......@@ -232,17 +223,7 @@ public class GSYRenderView {
mShowView = showSurfaceView;
int params = getTextureParams();
if (textureViewContainer instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(params, params);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
textureViewContainer.addView(showSurfaceView, layoutParams);
} else if (textureViewContainer instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(params, params);
layoutParams.gravity = Gravity.CENTER;
textureViewContainer.addView(showSurfaceView, layoutParams);
}
addToParent(textureViewContainer, showSurfaceView);
}
/**
......@@ -269,16 +250,20 @@ public class GSYRenderView {
gsyVideoGLView.setMVPMatrix(transform);
}
addToParent(textureViewContainer, gsyVideoGLView);
}
private void addToParent(ViewGroup textureViewContainer, View render) {
int params = getTextureParams();
if (textureViewContainer instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(params, params);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
textureViewContainer.addView(gsyVideoGLView, layoutParams);
textureViewContainer.addView(render, layoutParams);
} else if (textureViewContainer instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(params, params);
layoutParams.gravity = Gravity.CENTER;
textureViewContainer.addView(gsyVideoGLView, layoutParams);
textureViewContainer.addView(render, layoutParams);
}
}
......
......@@ -8,7 +8,6 @@ import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.MeasureHelper;
/**
*
* Created by guoshuyu on 2017/8/26.
*/
......@@ -31,25 +30,7 @@ public class GSYSurfaceView extends SurfaceView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (GSYVideoManager.instance().getMediaPlayer() != null) {
try {
int videoWidth = GSYVideoManager.instance().getCurrentVideoWidth();
int videoHeight = GSYVideoManager.instance().getCurrentVideoHeight();
int videoSarNum = GSYVideoManager.instance().getMediaPlayer().getVideoSarNum();
int videoSarDen = GSYVideoManager.instance().getMediaPlayer().getVideoSarDen();
if (videoWidth > 0 && videoHeight > 0) {
measureHelper.setVideoSampleAspectRatio(videoSarNum, videoSarDen);
measureHelper.setVideoSize(videoWidth, videoHeight);
}
measureHelper.setVideoRotation((int) getRotation());
measureHelper.doMeasure(widthMeasureSpec, heightMeasureSpec);
} catch (Exception e) {
e.printStackTrace();
}
}
measureHelper.prepareMeasure(widthMeasureSpec, heightMeasureSpec, (int) getRotation());
setMeasuredDimension(measureHelper.getMeasuredWidth(), measureHelper.getMeasuredHeight());
}
......
......@@ -34,24 +34,7 @@ public class GSYTextureView extends TextureView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (GSYVideoManager.instance().getMediaPlayer() != null) {
try {
int videoWidth = GSYVideoManager.instance().getCurrentVideoWidth();
int videoHeight = GSYVideoManager.instance().getCurrentVideoHeight();
int videoSarNum = GSYVideoManager.instance().getMediaPlayer().getVideoSarNum();
int videoSarDen = GSYVideoManager.instance().getMediaPlayer().getVideoSarDen();
if (videoWidth > 0 && videoHeight > 0) {
measureHelper.setVideoSampleAspectRatio(videoSarNum, videoSarDen);
measureHelper.setVideoSize(videoWidth, videoHeight);
}
measureHelper.setVideoRotation((int) getRotation());
measureHelper.doMeasure(widthMeasureSpec, heightMeasureSpec);
} catch (Exception e) {
e.printStackTrace();
}
}
measureHelper.prepareMeasure(widthMeasureSpec, heightMeasureSpec, (int) getRotation());
setMeasuredDimension(measureHelper.getMeasuredWidth(), measureHelper.getMeasuredHeight());
}
......
......@@ -107,24 +107,7 @@ public class GSYVideoGLView extends GLSurfaceView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (GSYVideoManager.instance().getMediaPlayer() != null) {
try {
int videoWidth = GSYVideoManager.instance().getCurrentVideoWidth();
int videoHeight = GSYVideoManager.instance().getCurrentVideoHeight();
int videoSarNum = GSYVideoManager.instance().getMediaPlayer().getVideoSarNum();
int videoSarDen = GSYVideoManager.instance().getMediaPlayer().getVideoSarDen();
if (videoWidth > 0 && videoHeight > 0) {
measureHelper.setVideoSampleAspectRatio(videoSarNum, videoSarDen);
measureHelper.setVideoSize(videoWidth, videoHeight);
}
measureHelper.setVideoRotation((int) getRotation());
measureHelper.doMeasure(widthMeasureSpec, heightMeasureSpec);
} catch (Exception e) {
e.printStackTrace();
}
}
measureHelper.prepareMeasure(widthMeasureSpec, heightMeasureSpec, (int) getRotation());
setMeasuredDimension(measureHelper.getMeasuredWidth(), measureHelper.getMeasuredHeight());
}
......
......@@ -19,6 +19,8 @@ package com.shuyu.gsyvideoplayer.utils;
import android.view.View;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import java.lang.ref.WeakReference;
public final class MeasureHelper {
......@@ -72,7 +74,7 @@ public final class MeasureHelper {
if (mVideoRotationDegree == 90 || mVideoRotationDegree == 270) {
int tempSpec = widthMeasureSpec;
widthMeasureSpec = heightMeasureSpec;
widthMeasureSpec = heightMeasureSpec;
heightMeasureSpec = tempSpec;
}
......@@ -103,7 +105,7 @@ public final class MeasureHelper {
break;
case GSYVideoType.SCREEN_TYPE_DEFAULT:
case GSYVideoType.SCREEN_TYPE_FULL:
//case GSYVideoType.AR_ASPECT_WRAP_CONTENT:
//case GSYVideoType.AR_ASPECT_WRAP_CONTENT:
default:
displayAspectRatio = (float) mVideoWidth / (float) mVideoHeight;
if (mVideoSarNum > 0 && mVideoSarDen > 0)
......@@ -202,6 +204,29 @@ public final class MeasureHelper {
mMeasuredHeight = height;
}
public void prepareMeasure(int widthMeasureSpec, int heightMeasureSpec, int rotate) {
if (GSYVideoManager.instance().getMediaPlayer() != null) {
try {
int videoWidth = GSYVideoManager.instance().getCurrentVideoWidth();
int videoHeight = GSYVideoManager.instance().getCurrentVideoHeight();
int videoSarNum = GSYVideoManager.instance().getMediaPlayer().getVideoSarNum();
int videoSarDen = GSYVideoManager.instance().getMediaPlayer().getVideoSarDen();
if (videoWidth > 0 && videoHeight > 0) {
setVideoSampleAspectRatio(videoSarNum, videoSarDen);
setVideoSize(videoWidth, videoHeight);
}
setVideoRotation(rotate);
doMeasure(widthMeasureSpec, heightMeasureSpec);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public int getMeasuredWidth() {
return mMeasuredWidth;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册