Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ac13
GSYVideoPlayer
提交
b8d37b19
G
GSYVideoPlayer
项目概览
ac13
/
GSYVideoPlayer
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
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 搜索 >>
提交
b8d37b19
编写于
5月 18, 2018
作者:
G
guoshuyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix exo
上级
1ece6db2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
277 addition
and
7 deletion
+277
-7
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/cache/ExoCacheManager.java
.../java/com/shuyu/gsyvideoplayer/cache/ExoCacheManager.java
+109
-0
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/ExoHelper.java
...o2/src/main/java/tv/danmaku/ijk/media/exo2/ExoHelper.java
+154
-0
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java
...in/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java
+14
-7
未找到文件。
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/cache/ExoCacheManager.java
0 → 100644
浏览文件 @
b8d37b19
package
com.shuyu.gsyvideoplayer.cache
;
import
android.content.Context
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
;
import
com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.cache.Cache
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
;
import
com.google.android.exoplayer2.upstream.cache.SimpleCache
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.File
;
import
java.util.Map
;
import
tv.danmaku.ijk.media.player.IMediaPlayer
;
/**
* Created by guoshuyu on 2018/5/18.
*/
public
class
ExoCacheManager
implements
ICacheManager
{
private
static
final
String
TAG
=
"ExoCacheManager"
;
private
Cache
mCache
;
protected
Map
<
String
,
String
>
mMapHeadData
;
@Override
public
void
doCacheLogic
(
Context
context
,
IMediaPlayer
mediaPlayer
,
String
url
,
Map
<
String
,
String
>
header
,
File
cachePath
)
{
}
@Override
public
void
clearCache
(
Context
context
,
String
url
)
{
}
@Override
public
void
release
()
{
if
(
mCache
!=
null
)
{
try
{
mCache
.
release
();
}
catch
(
Cache
.
CacheException
e
)
{
e
.
printStackTrace
();
}
}
}
@Override
public
boolean
hadCached
()
{
return
false
;
}
@Override
public
void
setCacheAvailableListener
(
ICacheAvailableListener
cacheAvailableListener
)
{
}
/**
* 本地缓存目录
*/
protected
Cache
getCache
(
Context
context
)
{
if
(
mCache
==
null
)
{
String
path
=
context
.
getCacheDir
().
getAbsolutePath
()
+
File
.
separator
+
"exo"
;
boolean
isLocked
=
SimpleCache
.
isCacheFolderLocked
(
new
File
(
path
));
if
(!
isLocked
)
{
mCache
=
new
SimpleCache
(
new
File
(
path
),
new
LeastRecentlyUsedCacheEvictor
(
1024
*
1024
*
100
));
}
}
return
mCache
;
}
/**
* 获取SourceFactory,是否带Cache
*/
private
DataSource
.
Factory
getDataSourceFactoryCache
(
Context
context
,
String
dataSource
,
boolean
cacheEnable
,
boolean
preview
)
{
if
(
cacheEnable
)
{
Cache
cache
=
getCache
(
context
);
return
new
CacheDataSourceFactory
(
cache
,
getDataSourceFactory
(
context
,
preview
),
CacheDataSource
.
FLAG_IGNORE_CACHE_ON_ERROR
);
}
else
{
return
getDataSourceFactory
(
context
,
preview
);
}
}
/**
* 获取SourceFactory
*/
private
DataSource
.
Factory
getDataSourceFactory
(
Context
context
,
boolean
preview
)
{
return
new
DefaultDataSourceFactory
(
context
,
preview
?
null
:
new
DefaultBandwidthMeter
(),
getHttpDataSourceFactory
(
context
,
preview
));
}
private
DataSource
.
Factory
getHttpDataSourceFactory
(
Context
context
,
boolean
preview
)
{
DefaultHttpDataSourceFactory
dataSourceFactory
=
new
DefaultHttpDataSourceFactory
(
Util
.
getUserAgent
(
context
,
TAG
),
preview
?
null
:
new
DefaultBandwidthMeter
());
if
(
mMapHeadData
!=
null
&&
mMapHeadData
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
String
>
header
:
mMapHeadData
.
entrySet
())
{
dataSourceFactory
.
getDefaultRequestProperties
().
set
(
header
.
getKey
(),
header
.
getValue
());
}
}
return
dataSourceFactory
;
}
}
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/ExoHelper.java
0 → 100644
浏览文件 @
b8d37b19
package
tv.danmaku.ijk.media.exo2
;
import
android.content.Context
;
import
android.net.Uri
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory
;
import
com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
;
import
com.google.android.exoplayer2.source.ExtractorMediaSource
;
import
com.google.android.exoplayer2.source.LoopingMediaSource
;
import
com.google.android.exoplayer2.source.MediaSource
;
import
com.google.android.exoplayer2.source.dash.DashMediaSource
;
import
com.google.android.exoplayer2.source.dash.DefaultDashChunkSource
;
import
com.google.android.exoplayer2.source.hls.HlsMediaSource
;
import
com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource
;
import
com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
;
import
com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.cache.Cache
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
;
import
com.google.android.exoplayer2.upstream.cache.SimpleCache
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.File
;
import
java.util.Map
;
/**
* Created by guoshuyu on 2018/5/18.
*/
public
class
ExoHelper
{
private
static
final
String
TAG
=
"IjkExo2MediaPlayer"
;
public
static
final
int
TYPE_RTMP
=
4
;
protected
Context
mAppContext
;
protected
Cache
mCache
;
protected
Map
<
String
,
String
>
mMapHeadData
;
public
ExoHelper
(
Context
context
,
Map
<
String
,
String
>
mapHeadData
)
{
mAppContext
=
context
.
getApplicationContext
();
mMapHeadData
=
mapHeadData
;
}
public
MediaSource
getMediaSource
(
String
dataSource
,
boolean
preview
,
boolean
cacheEnable
,
boolean
isLooping
)
{
Uri
contentUri
=
Uri
.
parse
(
dataSource
);
int
contentType
=
inferContentType
(
dataSource
);
MediaSource
mediaSource
;
switch
(
contentType
)
{
case
C
.
TYPE_SS
:
mediaSource
=
new
SsMediaSource
.
Factory
(
new
DefaultSsChunkSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
dataSource
,
cacheEnable
,
preview
)),
new
DefaultDataSourceFactory
(
mAppContext
,
null
,
getHttpDataSourceFactory
(
mAppContext
,
preview
))).
createMediaSource
(
contentUri
);
break
;
case
C
.
TYPE_DASH
:
mediaSource
=
new
DashMediaSource
.
Factory
(
new
DefaultDashChunkSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
dataSource
,
cacheEnable
,
preview
)),
new
DefaultDataSourceFactory
(
mAppContext
,
null
,
getHttpDataSourceFactory
(
mAppContext
,
preview
))).
createMediaSource
(
contentUri
);
break
;
case
C
.
TYPE_HLS
:
mediaSource
=
new
HlsMediaSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
dataSource
,
cacheEnable
,
preview
)).
createMediaSource
(
contentUri
);
break
;
case
TYPE_RTMP:
RtmpDataSourceFactory
rtmpDataSourceFactory
=
new
RtmpDataSourceFactory
(
null
);
mediaSource
=
new
ExtractorMediaSource
.
Factory
(
rtmpDataSourceFactory
)
.
setExtractorsFactory
(
new
DefaultExtractorsFactory
())
.
createMediaSource
(
contentUri
);
break
;
case
C
.
TYPE_OTHER
:
default
:
mediaSource
=
new
ExtractorMediaSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
dataSource
,
cacheEnable
,
preview
))
.
setExtractorsFactory
(
new
DefaultExtractorsFactory
())
.
createMediaSource
(
contentUri
);
break
;
}
if
(
isLooping
)
{
return
new
LoopingMediaSource
(
mediaSource
);
}
return
mediaSource
;
}
@C
.
ContentType
public
static
int
inferContentType
(
String
fileName
)
{
fileName
=
Util
.
toLowerInvariant
(
fileName
);
if
(
fileName
.
endsWith
(
".mpd"
))
{
return
C
.
TYPE_DASH
;
}
else
if
(
fileName
.
endsWith
(
".m3u8"
))
{
return
C
.
TYPE_HLS
;
}
else
if
(
fileName
.
endsWith
(
".ism"
)
||
fileName
.
endsWith
(
".isml"
)
||
fileName
.
endsWith
(
".ism/manifest"
)
||
fileName
.
endsWith
(
".isml/manifest"
))
{
return
C
.
TYPE_SS
;
}
else
if
(
fileName
.
startsWith
(
"rtmp:"
))
{
return
TYPE_RTMP
;
}
else
{
return
C
.
TYPE_OTHER
;
}
}
/**
* 本地缓存目录
*/
public
Cache
getCache
(
Context
context
)
{
if
(
mCache
==
null
)
{
String
path
=
context
.
getCacheDir
().
getAbsolutePath
()
+
File
.
separator
+
"exo"
;
boolean
isLocked
=
SimpleCache
.
isCacheFolderLocked
(
new
File
(
path
));
if
(!
isLocked
)
{
mCache
=
new
SimpleCache
(
new
File
(
path
),
new
LeastRecentlyUsedCacheEvictor
(
1024
*
1024
*
100
));
}
}
return
mCache
;
}
/**
* 获取SourceFactory,是否带Cache
*/
private
DataSource
.
Factory
getDataSourceFactoryCache
(
Context
context
,
String
dataSource
,
boolean
cacheEnable
,
boolean
preview
)
{
if
(
cacheEnable
)
{
Cache
cache
=
getCache
(
context
);
return
new
CacheDataSourceFactory
(
cache
,
getDataSourceFactory
(
context
,
preview
),
CacheDataSource
.
FLAG_IGNORE_CACHE_ON_ERROR
);
}
else
{
return
getDataSourceFactory
(
context
,
preview
);
}
}
/**
* 获取SourceFactory
*/
private
DataSource
.
Factory
getDataSourceFactory
(
Context
context
,
boolean
preview
)
{
return
new
DefaultDataSourceFactory
(
context
,
preview
?
null
:
new
DefaultBandwidthMeter
(),
getHttpDataSourceFactory
(
context
,
preview
));
}
private
DataSource
.
Factory
getHttpDataSourceFactory
(
Context
context
,
boolean
preview
)
{
DefaultHttpDataSourceFactory
dataSourceFactory
=
new
DefaultHttpDataSourceFactory
(
Util
.
getUserAgent
(
context
,
TAG
),
preview
?
null
:
new
DefaultBandwidthMeter
());
if
(
mMapHeadData
!=
null
&&
mMapHeadData
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
String
>
header
:
mMapHeadData
.
entrySet
())
{
dataSourceFactory
.
getDefaultRequestProperties
().
set
(
header
.
getKey
(),
header
.
getValue
());
}
}
return
dataSourceFactory
;
}
}
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java
浏览文件 @
b8d37b19
...
...
@@ -100,6 +100,7 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
private
boolean
mIsPrepareing
=
true
;
private
boolean
mIsBuffering
=
false
;
private
boolean
isLooping
=
false
;
private
boolean
isPreview
=
false
;
private
int
audioSessionId
=
C
.
AUDIO_SESSION_ID_UNSET
;
...
...
@@ -138,11 +139,6 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
if
(
surface
!=
null
&&
!
surface
.
isValid
())
{
mSurface
=
null
;
}
/*if (mSurface == null) {
mTrackSelector.setParameters(mTrackSelector.buildUponParameters().setRendererDisabled(getVideoRendererIndex(), true));
} else {
mTrackSelector.setParameters(mTrackSelector.buildUponParameters().setRendererDisabled(getVideoRendererIndex(), false));
}*/
mInternalPlayer
.
setVideoSurface
(
surface
);
}
}
...
...
@@ -150,12 +146,11 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
@Override
public
void
setDataSource
(
Context
context
,
Uri
uri
)
{
mDataSource
=
uri
.
toString
();
mMediaSource
=
getMediaSource
(
false
);
mMediaSource
=
getMediaSource
(
isPreview
);
}
@Override
public
void
setDataSource
(
Context
context
,
Uri
uri
,
Map
<
String
,
String
>
headers
)
{
// TODO: handle headers
mHeaders
=
headers
;
setDataSource
(
context
,
uri
);
}
...
...
@@ -375,6 +370,18 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
mInternalPlayer
.
stop
();
}
public
void
setPreview
(
boolean
preview
)
{
isPreview
=
preview
;
}
public
MediaSource
getMediaSource
()
{
return
mMediaSource
;
}
public
void
setMediaSource
(
MediaSource
mediaSource
)
{
this
.
mMediaSource
=
mediaSource
;
}
/**
* 倍速播放
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录