Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_26386469
GSYVideoPlayer
提交
d25bd553
G
GSYVideoPlayer
项目概览
qq_26386469
/
GSYVideoPlayer
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
GSYVideoPlayer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d25bd553
编写于
8月 26, 2017
作者:
S
shuyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加了SurfaceView的支持 (2017-08-26)
上级
32c084ec
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
271 addition
and
29 deletion
+271
-29
app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java
.../main/java/com/example/gsyvideoplayer/GSYApplication.java
+1
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYRenderView.java
...src/main/java/com/shuyu/gsyvideoplayer/GSYRenderView.java
+139
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYSurfaceView.java
...rc/main/java/com/shuyu/gsyvideoplayer/GSYSurfaceView.java
+57
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/utils/GSYVideoType.java
...ain/java/com/shuyu/gsyvideoplayer/utils/GSYVideoType.java
+21
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYTextureRenderView.java
...shuyu/gsyvideoplayer/video/base/GSYTextureRenderView.java
+53
-29
未找到文件。
app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java
浏览文件 @
d25bd553
...
...
@@ -26,5 +26,6 @@ public class GSYApplication extends Application {
//GSYVideoManager.instance().setVideoType(this, GSYVideoType.IJKEXOPLAYER);
//GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);
//GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL);
//GSYVideoType.setRenderType(GSYVideoType.SUFRACE);
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYRenderView.java
0 → 100644
浏览文件 @
d25bd553
package
com.shuyu.gsyvideoplayer
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Matrix
;
import
android.view.Gravity
;
import
android.view.SurfaceHolder
;
import
android.view.TextureView
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.FrameLayout
;
import
android.widget.RelativeLayout
;
import
com.shuyu.gsyvideoplayer.utils.GSYVideoType
;
/**
* render绘制中间控件
* Created by guoshuyu on 2017/8/26.
*/
public
class
GSYRenderView
{
private
View
mShowView
;
public
void
setTransform
(
Matrix
transform
)
{
if
(
mShowView
instanceof
TextureView
)
{
((
TextureView
)
mShowView
).
setTransform
(
transform
);
}
}
public
void
requestLayout
()
{
mShowView
.
requestLayout
();
}
public
float
getRotation
()
{
return
mShowView
.
getRotation
();
}
public
void
setRotation
(
float
rotation
)
{
mShowView
.
setRotation
(
rotation
);
}
public
void
invalidate
()
{
mShowView
.
invalidate
();
}
public
int
getWidth
()
{
return
mShowView
.
getWidth
();
}
public
int
getHeight
()
{
return
mShowView
.
getHeight
();
}
/**
* 暂停时初始化位图
*/
public
Bitmap
initCover
()
{
if
(
mShowView
!=
null
&&
mShowView
instanceof
GSYTextureView
)
{
GSYTextureView
textureView
=
(
GSYTextureView
)
mShowView
;
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
textureView
.
getSizeW
(),
textureView
.
getSizeH
(),
Bitmap
.
Config
.
RGB_565
);
return
textureView
.
getBitmap
(
bitmap
);
}
return
null
;
}
public
ViewGroup
.
LayoutParams
getLayoutParams
()
{
return
mShowView
.
getLayoutParams
();
}
public
void
setLayoutParams
(
ViewGroup
.
LayoutParams
layoutParams
)
{
mShowView
.
setLayoutParams
(
layoutParams
);
}
/**
* 添加播放的view
*/
public
void
addTextureView
(
Context
context
,
ViewGroup
textureViewContainer
,
int
rotate
,
TextureView
.
SurfaceTextureListener
listener
)
{
if
(
textureViewContainer
.
getChildCount
()
>
0
)
{
textureViewContainer
.
removeAllViews
();
}
GSYTextureView
gsyTextureView
=
new
GSYTextureView
(
context
);
gsyTextureView
.
setSurfaceTextureListener
(
listener
);
gsyTextureView
.
setRotation
(
rotate
);
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
);
}
}
/**
* 添加播放的view
*/
public
void
addSurfaceView
(
Context
context
,
ViewGroup
textureViewContainer
,
int
rotate
,
SurfaceHolder
.
Callback2
callback2
)
{
if
(
textureViewContainer
.
getChildCount
()
>
0
)
{
textureViewContainer
.
removeAllViews
();
}
GSYSurfaceView
showSurfaceView
=
new
GSYSurfaceView
(
context
);
showSurfaceView
.
getHolder
().
addCallback
(
callback2
);
showSurfaceView
.
setRotation
(
rotate
);
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
);
}
}
/**
* 获取布局参数
*
* @return
*/
protected
int
getTextureParams
()
{
boolean
typeChanged
=
(
GSYVideoType
.
getShowType
()
!=
GSYVideoType
.
SCREEN_TYPE_DEFAULT
);
return
(
typeChanged
)
?
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
:
ViewGroup
.
LayoutParams
.
MATCH_PARENT
;
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYSurfaceView.java
0 → 100644
浏览文件 @
d25bd553
package
com.shuyu.gsyvideoplayer
;
import
android.content.Context
;
import
android.util.AttributeSet
;
import
android.view.SurfaceView
;
import
com.shuyu.gsyvideoplayer.utils.MeasureHelper
;
/**
*
* Created by guoshuyu on 2017/8/26.
*/
public
class
GSYSurfaceView
extends
SurfaceView
{
private
MeasureHelper
measureHelper
;
public
GSYSurfaceView
(
Context
context
)
{
super
(
context
);
init
();
}
public
GSYSurfaceView
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
init
();
}
private
void
init
()
{
measureHelper
=
new
MeasureHelper
(
this
);
}
@Override
protected
void
onMeasure
(
int
widthMeasureSpec
,
int
heightMeasureSpec
)
{
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
);
setMeasuredDimension
(
measureHelper
.
getMeasuredWidth
(),
measureHelper
.
getMeasuredHeight
());
}
public
int
getSizeH
()
{
return
measureHelper
.
getMeasuredHeight
();
}
public
int
getSizeW
()
{
return
measureHelper
.
getMeasuredWidth
();
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/utils/GSYVideoType.java
浏览文件 @
d25bd553
...
...
@@ -26,6 +26,11 @@ public class GSYVideoType {
public
final
static
int
IJKEXOPLAYER
=
1
;
//surface
public
final
static
int
SUFRACE
=
1
;
//texture
public
final
static
int
TEXTURE
=
0
;
//显示比例类型
...
...
@@ -35,6 +40,8 @@ public class GSYVideoType {
private
static
boolean
MEDIA_CODEC_FLAG
=
false
;
private
static
int
sRenderType
=
TEXTURE
;
/**
* 使能硬解码,播放前设置
...
...
@@ -67,4 +74,18 @@ public class GSYVideoType {
public
static
void
setShowType
(
int
type
)
{
TYPE
=
type
;
}
public
static
int
getRenderType
()
{
return
sRenderType
;
}
/**
* 渲染控件
*
* @param renderType
*/
public
static
void
setRenderType
(
int
renderType
)
{
sRenderType
=
renderType
;
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYTextureRenderView.java
浏览文件 @
d25bd553
...
...
@@ -9,11 +9,16 @@ import android.support.annotation.Nullable;
import
android.util.AttributeSet
;
import
android.view.Gravity
;
import
android.view.Surface
;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceView
;
import
android.view.TextureView
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.FrameLayout
;
import
android.widget.RelativeLayout
;
import
com.shuyu.gsyvideoplayer.GSYRenderView
;
import
com.shuyu.gsyvideoplayer.GSYSurfaceView
;
import
com.shuyu.gsyvideoplayer.GSYTextureView
;
import
com.shuyu.gsyvideoplayer.GSYVideoManager
;
import
com.shuyu.gsyvideoplayer.utils.GSYVideoType
;
...
...
@@ -23,13 +28,13 @@ import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
* Created by guoshuyu on 2017/8/2.
*/
public
abstract
class
GSYTextureRenderView
extends
FrameLayout
implements
TextureView
.
SurfaceTextureListener
{
public
abstract
class
GSYTextureRenderView
extends
FrameLayout
implements
TextureView
.
SurfaceTextureListener
,
SurfaceHolder
.
Callback2
{
//native绘制
protected
Surface
mSurface
;
//渲染控件
protected
GSY
Texture
View
mTextureView
;
protected
GSY
Render
View
mTextureView
;
//渲染控件父类
protected
ViewGroup
mTextureViewContainer
;
...
...
@@ -52,15 +57,12 @@ public abstract class GSYTextureRenderView extends FrameLayout implements Textur
super
(
context
,
attrs
,
defStyleAttr
);
}
/******************** TextureView ****************************/
@Override
public
void
onSurfaceTextureAvailable
(
SurfaceTexture
surface
,
int
width
,
int
height
)
{
mSurface
=
new
Surface
(
surface
);
//显示暂停切换显示的图片
showPauseCover
();
GSYVideoManager
.
instance
().
setDisplay
(
mSurface
);
Surface
newSurface
=
new
Surface
(
surface
);
pauseLogic
(
newSurface
,
true
);
}
@Override
...
...
@@ -82,33 +84,58 @@ public abstract class GSYTextureRenderView extends FrameLayout implements Textur
releasePauseCover
();
}
/******************** SurfaceView ****************************/
@Override
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
pauseLogic
(
holder
.
getSurface
(),
false
);
}
@Override
public
void
surfaceChanged
(
SurfaceHolder
holder
,
int
format
,
int
width
,
int
height
)
{
}
@Override
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
//清空释放
GSYVideoManager
.
instance
().
setDisplay
(
null
);
holder
.
getSurface
().
release
();
}
@Override
public
void
surfaceRedrawNeeded
(
SurfaceHolder
holder
)
{
}
/**
* 暂停逻辑
*/
protected
void
pauseLogic
(
Surface
surface
,
boolean
pauseLogic
)
{
mSurface
=
surface
;
if
(
pauseLogic
)
//显示暂停切换显示的图片
showPauseCover
();
GSYVideoManager
.
instance
().
setDisplay
(
mSurface
);
}
/**
* 添加播放的view
*/
protected
void
addTextureView
()
{
if
(
mTextureViewContainer
.
getChildCount
()
>
0
)
{
mTextureViewContainer
.
removeAllViews
();
}
mTextureView
=
null
;
mTextureView
=
new
GSYTextureView
(
getContext
());
mTextureView
.
setSurfaceTextureListener
(
this
);
mTextureView
.
setRotation
(
mRotate
);
int
params
=
getTextureParams
();
mTextureView
=
new
GSYRenderView
();
if
(
mTextureViewContainer
instanceof
RelativeLayout
)
{
RelativeLayout
.
LayoutParams
layoutParams
=
new
RelativeLayout
.
LayoutParams
(
params
,
params
);
layoutParams
.
addRule
(
RelativeLayout
.
CENTER_IN_PARENT
);
mTextureViewContainer
.
addView
(
mTextureView
,
layoutParams
);
}
else
if
(
mTextureViewContainer
instanceof
FrameLayout
)
{
LayoutParams
layoutParams
=
new
LayoutParams
(
params
,
params
);
layoutParams
.
gravity
=
Gravity
.
CENTER
;
mTextureViewContainer
.
addView
(
mTextureView
,
layoutParams
);
if
(
GSYVideoType
.
getRenderType
()
==
GSYVideoType
.
SUFRACE
)
{
mTextureView
.
addSurfaceView
(
getContext
(),
mTextureViewContainer
,
mRotate
,
this
);
return
;
}
mTextureView
.
addTextureView
(
getContext
(),
mTextureViewContainer
,
mRotate
,
this
);
}
/**
* 获取布局参数
*
* @return
*/
protected
int
getTextureParams
()
{
...
...
@@ -131,10 +158,7 @@ public abstract class GSYTextureRenderView extends FrameLayout implements Textur
* 暂停时初始化位图
*/
protected
void
initCover
()
{
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
mTextureView
.
getSizeW
(),
mTextureView
.
getSizeH
(),
Bitmap
.
Config
.
RGB_565
);
mFullPauseBitmap
=
mTextureView
.
getBitmap
(
bitmap
);
//bitmap.recycle();
mFullPauseBitmap
=
mTextureView
.
initCover
();
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录