Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_25606643
ijkplayer
提交
84426ee5
I
ijkplayer
项目概览
qq_25606643
/
ijkplayer
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
ijkplayer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84426ee5
编写于
8月 21, 2015
作者:
Z
Zhang Rui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
android/ui: toggle render
上级
4cd8a025
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
191 addition
and
25 deletion
+191
-25
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/activities/VideoActivity.java
...tv/danmaku/ijk/media/sample/activities/VideoActivity.java
+11
-4
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/IRenderView.java
...tv/danmaku/ijk/media/sample/widget/media/IRenderView.java
+4
-0
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/IjkVideoView.java
...v/danmaku/ijk/media/sample/widget/media/IjkVideoView.java
+141
-19
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/MeasureHelper.java
.../danmaku/ijk/media/sample/widget/media/MeasureHelper.java
+2
-0
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/SurfaceRenderView.java
...maku/ijk/media/sample/widget/media/SurfaceRenderView.java
+10
-0
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/TextureRenderView.java
...maku/ijk/media/sample/widget/media/TextureRenderView.java
+10
-0
android/ijkplayer/sample/src/main/res/drawable-hdpi/ic_action_dark_filter.png
...mple/src/main/res/drawable-hdpi/ic_action_dark_filter.png
+0
-0
android/ijkplayer/sample/src/main/res/drawable-mdpi/ic_action_dark_filter.png
...mple/src/main/res/drawable-mdpi/ic_action_dark_filter.png
+0
-0
android/ijkplayer/sample/src/main/res/drawable-xhdpi/ic_action_dark_filter.png
...ple/src/main/res/drawable-xhdpi/ic_action_dark_filter.png
+0
-0
android/ijkplayer/sample/src/main/res/drawable-xxhdpi/ic_action_dark_filter.png
...le/src/main/res/drawable-xxhdpi/ic_action_dark_filter.png
+0
-0
android/ijkplayer/sample/src/main/res/drawable-xxxhdpi/ic_action_dark_filter.png
...e/src/main/res/drawable-xxxhdpi/ic_action_dark_filter.png
+0
-0
android/ijkplayer/sample/src/main/res/layout/activity_player.xml
.../ijkplayer/sample/src/main/res/layout/activity_player.xml
+1
-1
android/ijkplayer/sample/src/main/res/menu/menu_player.xml
android/ijkplayer/sample/src/main/res/menu/menu_player.xml
+6
-1
android/ijkplayer/sample/src/main/res/values/strings.xml
android/ijkplayer/sample/src/main/res/values/strings.xml
+6
-0
未找到文件。
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/activities/VideoActivity.java
浏览文件 @
84426ee5
...
...
@@ -38,7 +38,7 @@ public class VideoActivity extends AppCompatActivity {
private
AndroidMediaController
mMediaController
;
private
IjkVideoView
mVideoView
;
private
TextView
m
ScaleMode
TextView
;
private
TextView
m
Toast
TextView
;
public
static
Intent
newIntent
(
Context
context
,
String
videoPath
,
String
videoTitle
)
{
Intent
intent
=
new
Intent
(
context
,
VideoActivity
.
class
);
...
...
@@ -73,7 +73,7 @@ public class VideoActivity extends AppCompatActivity {
mMediaController
=
new
AndroidMediaController
(
this
,
false
);
mMediaController
.
setSupportActionBar
(
actionBar
);
m
ScaleModeTextView
=
(
TextView
)
findViewById
(
R
.
id
.
scale_mode
_text_view
);
m
ToastTextView
=
(
TextView
)
findViewById
(
R
.
id
.
toast
_text_view
);
// init player
IjkMediaPlayer
.
loadLibrariesOnce
(
null
);
...
...
@@ -90,6 +90,7 @@ public class VideoActivity extends AppCompatActivity {
super
.
onStop
();
mVideoView
.
stopPlayback
();
mVideoView
.
release
(
true
);
IjkMediaPlayer
.
native_profileEnd
();
}
...
...
@@ -105,8 +106,14 @@ public class VideoActivity extends AppCompatActivity {
if
(
id
==
R
.
id
.
action_toggle_ratio
)
{
int
aspectRatio
=
mVideoView
.
toggleAspectRatio
();
String
aspectRatioText
=
MeasureHelper
.
getAspectRatioText
(
this
,
aspectRatio
);
mScaleModeTextView
.
setText
(
aspectRatioText
);
mMediaController
.
showOnce
(
mScaleModeTextView
);
mToastTextView
.
setText
(
aspectRatioText
);
mMediaController
.
showOnce
(
mToastTextView
);
return
true
;
}
else
if
(
id
==
R
.
id
.
action_toggle_render
)
{
int
render
=
mVideoView
.
toggleRender
();
String
renderText
=
IjkVideoView
.
getRenderText
(
this
,
render
);
mToastTextView
.
setText
(
renderText
);
mMediaController
.
showOnce
(
mToastTextView
);
return
true
;
}
...
...
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/IRenderView.java
浏览文件 @
84426ee5
...
...
@@ -23,6 +23,8 @@ import android.view.Surface;
import
android.view.SurfaceHolder
;
import
android.view.View
;
import
tv.danmaku.ijk.media.player.IMediaPlayer
;
public
interface
IRenderView
{
static
final
int
AR_ASPECT_FIT_PARENT
=
0
;
// without clip
static
final
int
AR_ASPECT_FILL_PARENT
=
1
;
// may clip
...
...
@@ -44,6 +46,8 @@ public interface IRenderView {
void
removeRenderCallback
(
@NonNull
IRenderCallback
callback
);
interface
ISurfaceHolder
{
void
bindToMediaPlayer
(
IMediaPlayer
mp
);
@NonNull
IRenderView
getRenderView
();
...
...
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/IjkVideoView.java
浏览文件 @
84426ee5
...
...
@@ -37,6 +37,7 @@ import android.widget.FrameLayout;
import
android.widget.MediaController
;
import
java.io.IOException
;
import
java.util.Locale
;
import
java.util.Map
;
import
tv.danmaku.ijk.media.player.AndroidMediaPlayer
;
...
...
@@ -132,23 +133,11 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
mSettings
=
new
Settings
(
mAppContext
);
if
(
mSettings
.
getUsingTextureView
()
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
ICE_CREAM_SANDWICH
)
{
TextureRenderView
renderView
=
new
TextureRenderView
(
context
);
mRenderView
=
renderView
;
setRender
(
RENDER_TEXTURE_VIEW
);
}
else
{
SurfaceRenderView
renderView
=
new
SurfaceRenderView
(
context
);
mRenderView
=
renderView
;
setRender
(
RENDER_SURFACE_VIEW
);
}
View
renderView
=
mRenderView
.
getView
();
FrameLayout
.
LayoutParams
lp
=
new
FrameLayout
.
LayoutParams
(
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
,
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
,
Gravity
.
CENTER
);
renderView
.
setLayoutParams
(
lp
);
addView
(
renderView
);
mRenderView
.
addRenderCallback
(
mSHCallback
);
mVideoWidth
=
0
;
mVideoHeight
=
0
;
// REMOVED: getHolder().addCallback(mSHCallback);
...
...
@@ -161,6 +150,58 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
mTargetState
=
STATE_IDLE
;
}
public
void
setRenderView
(
IRenderView
renderView
)
{
if
(
mRenderView
!=
null
)
{
View
renderUIView
=
mRenderView
.
getView
();
mRenderView
.
removeRenderCallback
(
mSHCallback
);
mRenderView
=
null
;
removeView
(
renderUIView
);
if
(
mMediaPlayer
!=
null
)
mMediaPlayer
.
setDisplay
(
null
);
}
if
(
renderView
==
null
)
return
;
mRenderView
=
renderView
;
renderView
.
setAspectRatio
(
mCurrentAspectRatio
);
if
(
mVideoWidth
>
0
&&
mVideoHeight
>
0
)
renderView
.
setVideoSize
(
mVideoWidth
,
mVideoHeight
);
if
(
mVideoSarNum
>
0
&&
mVideoHeight
>
0
)
renderView
.
setVideoSampleAspectRatio
(
mVideoWidth
,
mVideoHeight
);
View
renderUIView
=
mRenderView
.
getView
();
FrameLayout
.
LayoutParams
lp
=
new
FrameLayout
.
LayoutParams
(
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
,
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
,
Gravity
.
CENTER
);
renderUIView
.
setLayoutParams
(
lp
);
addView
(
renderUIView
);
mRenderView
.
addRenderCallback
(
mSHCallback
);
}
public
void
setRender
(
int
render
)
{
switch
(
render
)
{
case
RENDER_NONE:
setRenderView
(
null
);
break
;
case
RENDER_TEXTURE_VIEW:
{
TextureRenderView
renderView
=
new
TextureRenderView
(
getContext
());
setRenderView
(
renderView
);
break
;
}
case
RENDER_SURFACE_VIEW:
{
SurfaceRenderView
renderView
=
new
SurfaceRenderView
(
getContext
());
setRenderView
(
renderView
);
break
;
}
default
:
Log
.
e
(
TAG
,
String
.
format
(
Locale
.
getDefault
(),
"invalid render %d\n"
,
render
));
break
;
}
}
/**
* Sets video path.
*
...
...
@@ -521,9 +562,26 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
}
// REMOVED: mSHCallback
private
void
bindSurfaceHolder
(
IMediaPlayer
mp
,
IRenderView
.
ISurfaceHolder
holder
)
{
if
(
mp
==
null
)
return
;
if
(
holder
==
null
)
{
mp
.
setDisplay
(
null
);
return
;
}
holder
.
bindToMediaPlayer
(
mp
);
}
IRenderView
.
IRenderCallback
mSHCallback
=
new
IRenderView
.
IRenderCallback
()
{
@Override
public
void
onSurfaceChanged
(
@NonNull
IRenderView
.
ISurfaceHolder
holder
,
int
format
,
int
w
,
int
h
)
{
if
(
holder
==
null
||
holder
.
getRenderView
()
!=
mRenderView
)
{
Log
.
e
(
TAG
,
"onSurfaceChanged: unmatched render callback\n"
);
return
;
}
mSurfaceWidth
=
w
;
mSurfaceHeight
=
h
;
boolean
isValidState
=
(
mTargetState
==
STATE_PLAYING
);
...
...
@@ -538,23 +596,42 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
@Override
public
void
onSurfaceCreated
(
@NonNull
IRenderView
.
ISurfaceHolder
holder
,
int
width
,
int
height
)
{
if
(
holder
==
null
||
holder
.
getRenderView
()
!=
mRenderView
)
{
Log
.
e
(
TAG
,
"onSurfaceCreated: unmatched render callback\n"
);
return
;
}
mSurfaceHolder
=
holder
;
openVideo
();
if
(
mMediaPlayer
!=
null
)
bindSurfaceHolder
(
mMediaPlayer
,
holder
);
else
openVideo
();
}
@Override
public
void
onSurfaceDestroyed
(
@NonNull
IRenderView
.
ISurfaceHolder
holder
)
{
if
(
holder
==
null
&&
holder
.
getRenderView
()
!=
mRenderView
)
{
Log
.
e
(
TAG
,
"onSurfaceDestroyed: unmatched render callback\n"
);
return
;
}
// after we return from this we can't use the surface any more
mSurfaceHolder
=
null
;
if
(
mMediaController
!=
null
)
mMediaController
.
hide
();
release
(
true
);
// REMOVED: if (mMediaController != null) mMediaController.hide();
// REMOVED: release(true);
releaseWithoutStop
();
}
};
public
void
releaseWithoutStop
()
{
if
(
mMediaPlayer
!=
null
)
mMediaPlayer
.
setDisplay
(
null
);
}
/*
* release the media player in any state
*/
p
rivate
void
release
(
boolean
cleartargetstate
)
{
p
ublic
void
release
(
boolean
cleartargetstate
)
{
if
(
mMediaPlayer
!=
null
)
{
mMediaPlayer
.
reset
();
mMediaPlayer
.
release
();
...
...
@@ -757,7 +834,52 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
mCurrentAspectRatioIndex
%=
s_allAspectRatio
.
length
;
mCurrentAspectRatio
=
s_allAspectRatio
[
mCurrentAspectRatioIndex
];
mRenderView
.
setAspectRatio
(
mCurrentAspectRatio
);
if
(
mRenderView
!=
null
)
mRenderView
.
setAspectRatio
(
mCurrentAspectRatio
);
return
mCurrentAspectRatio
;
}
//-------------------------
// Extend: Render
//-------------------------
public
static
final
int
RENDER_NONE
=
0
;
public
static
final
int
RENDER_SURFACE_VIEW
=
1
;
public
static
final
int
RENDER_TEXTURE_VIEW
=
2
;
private
static
final
int
[]
s_allRender
=
{
RENDER_SURFACE_VIEW
,
// RENDER_TEXTURE_VIEW,
RENDER_NONE
};
private
int
mCurrentRenderIndex
=
0
;
private
int
mCurrentRender
=
s_allRender
[
0
];
public
int
toggleRender
()
{
mCurrentRenderIndex
++;
mCurrentRenderIndex
%=
s_allRender
.
length
;
mCurrentRender
=
s_allRender
[
mCurrentRenderIndex
];
setRender
(
mCurrentRender
);
return
mCurrentRender
;
}
@NonNull
public
static
String
getRenderText
(
Context
context
,
int
render
)
{
String
text
;
switch
(
render
)
{
case
RENDER_NONE:
text
=
context
.
getString
(
R
.
string
.
VideoView_render_none
);
break
;
case
RENDER_SURFACE_VIEW:
text
=
context
.
getString
(
R
.
string
.
VideoView_render_surface_view
);
break
;
case
RENDER_TEXTURE_VIEW:
text
=
context
.
getString
(
R
.
string
.
VideoView_render_texture_view
);
break
;
default
:
text
=
context
.
getString
(
R
.
string
.
N_A
);
break
;
}
return
text
;
}
}
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/MeasureHelper.java
浏览文件 @
84426ee5
...
...
@@ -17,6 +17,7 @@
package
tv.danmaku.ijk.media.sample.widget.media
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
android.view.View
;
import
java.lang.ref.WeakReference
;
...
...
@@ -201,6 +202,7 @@ public final class MeasureHelper {
mCurrentAspectRatio
=
aspectRatio
;
}
@NonNull
public
static
String
getAspectRatioText
(
Context
context
,
int
aspectRatio
)
{
String
text
;
switch
(
aspectRatio
)
{
...
...
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/SurfaceRenderView.java
浏览文件 @
84426ee5
...
...
@@ -34,6 +34,8 @@ import java.lang.ref.WeakReference;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
tv.danmaku.ijk.media.player.IMediaPlayer
;
public
class
SurfaceRenderView
extends
SurfaceView
implements
IRenderView
{
private
MeasureHelper
mMeasureHelper
;
...
...
@@ -116,6 +118,12 @@ public class SurfaceRenderView extends SurfaceView implements IRenderView {
mSurfaceHolder
=
surfaceHolder
;
}
public
void
bindToMediaPlayer
(
IMediaPlayer
mp
)
{
if
(
mp
!=
null
)
{
mp
.
setDisplay
(
mSurfaceHolder
);
}
}
@NonNull
@Override
public
IRenderView
getRenderView
()
{
...
...
@@ -137,6 +145,8 @@ public class SurfaceRenderView extends SurfaceView implements IRenderView {
@Nullable
@Override
public
Surface
openSurface
()
{
if
(
mSurfaceHolder
==
null
)
return
null
;
return
mSurfaceHolder
.
getSurface
();
}
}
...
...
android/ijkplayer/sample/src/main/java/tv/danmaku/ijk/media/sample/widget/media/TextureRenderView.java
浏览文件 @
84426ee5
...
...
@@ -34,6 +34,8 @@ import java.lang.ref.WeakReference;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
tv.danmaku.ijk.media.player.IMediaPlayer
;
@TargetApi
(
Build
.
VERSION_CODES
.
ICE_CREAM_SANDWICH
)
public
class
TextureRenderView
extends
TextureView
implements
IRenderView
{
private
MeasureHelper
mMeasureHelper
;
...
...
@@ -114,6 +116,12 @@ public class TextureRenderView extends TextureView implements IRenderView {
mSurfaceTexture
=
surfaceTexture
;
}
public
void
bindToMediaPlayer
(
IMediaPlayer
mp
)
{
if
(
mp
!=
null
)
{
mp
.
setSurface
(
openSurface
());
}
}
@NonNull
@Override
public
IRenderView
getRenderView
()
{
...
...
@@ -135,6 +143,8 @@ public class TextureRenderView extends TextureView implements IRenderView {
@Nullable
@Override
public
Surface
openSurface
()
{
if
(
mSurfaceTexture
==
null
)
return
null
;
return
new
Surface
(
mSurfaceTexture
);
}
}
...
...
android/ijkplayer/sample/src/main/res/drawable-hdpi/ic_action_dark_filter.png
0 → 100755
浏览文件 @
84426ee5
767 字节
android/ijkplayer/sample/src/main/res/drawable-mdpi/ic_action_dark_filter.png
0 → 100755
浏览文件 @
84426ee5
490 字节
android/ijkplayer/sample/src/main/res/drawable-xhdpi/ic_action_dark_filter.png
0 → 100755
浏览文件 @
84426ee5
929 字节
android/ijkplayer/sample/src/main/res/drawable-xxhdpi/ic_action_dark_filter.png
0 → 100755
浏览文件 @
84426ee5
1.5 KB
android/ijkplayer/sample/src/main/res/drawable-xxxhdpi/ic_action_dark_filter.png
0 → 100755
浏览文件 @
84426ee5
2.1 KB
android/ijkplayer/sample/src/main/res/layout/activity_player.xml
浏览文件 @
84426ee5
...
...
@@ -23,7 +23,7 @@
tools:context=
".toolbar_widget"
/>
<TextView
android:id=
"@+id/
scale_mode
_text_view"
android:id=
"@+id/
toast
_text_view"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"left|center_vertical"
...
...
android/ijkplayer/sample/src/main/res/menu/menu_player.xml
浏览文件 @
84426ee5
...
...
@@ -3,9 +3,14 @@
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
tools:context=
".menu_app"
>
<item
android:id=
"@+id/action_toggle_render"
android:title=
"@string/toggle_render"
android:icon=
"@drawable/ic_action_dark_filter"
app:showAsAction=
"ifRoom"
/>
<item
android:id=
"@+id/action_toggle_ratio"
android:title=
"@string/
settings
"
android:title=
"@string/
toggle_ratio
"
android:icon=
"@drawable/ic_action_dark_aspect_ratio"
app:showAsAction=
"ifRoom"
/>
</menu>
\ No newline at end of file
android/ijkplayer/sample/src/main/res/values/strings.xml
浏览文件 @
84426ee5
...
...
@@ -5,6 +5,8 @@
<string
name=
"N_A"
>
N/A
</string>
<string
name=
"settings"
>
Settings
</string>
<string
name=
"toggle_render"
>
Toggle Render
</string>
<string
name=
"toggle_ratio"
>
Toggle Ratio
</string>
<string
name=
"VideoView_error_text_invalid_progressive_playback"
>
Invalid progressive playback
</string>
<string
name=
"VideoView_error_text_unknown"
>
Unknown
</string>
...
...
@@ -17,4 +19,8 @@
<string
name=
"VideoView_ar_16_9_fit_parent"
>
16:9 / Fit parent
</string>
<string
name=
"VideoView_ar_4_3_fit_parent"
>
4:3 / Fit parent
</string>
<string
name=
"VideoView_render_none"
>
Render: None
</string>
<string
name=
"VideoView_render_surface_view"
>
Render: SurfaceView
</string>
<string
name=
"VideoView_render_texture_view"
>
Render: TextureView
</string>
</resources>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录