Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NotesChapter
GSYVideoPlayer
提交
0284d70e
G
GSYVideoPlayer
项目概览
NotesChapter
/
GSYVideoPlayer
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
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,发现更多精彩内容 >>
提交
0284d70e
编写于
5月 19, 2018
作者:
S
shuyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调整exo的cache机制
上级
6d700081
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
100 addition
and
56 deletion
+100
-56
README.md
README.md
+1
-1
app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java
.../main/java/com/example/gsyvideoplayer/GSYApplication.java
+1
-1
app/src/main/java/com/example/gsyvideoplayer/adapter/ListNormalAdapter.java
...com/example/gsyvideoplayer/adapter/ListNormalAdapter.java
+2
-2
app/src/main/java/com/example/gsyvideoplayer/exo/GSYExoPlayerManager.java
...a/com/example/gsyvideoplayer/exo/GSYExoPlayerManager.java
+8
-1
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoBaseManager.java
...in/java/com/shuyu/gsyvideoplayer/GSYVideoBaseManager.java
+9
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/EXO2PlayerManager.java
...va/com/shuyu/gsyvideoplayer/player/EXO2PlayerManager.java
+13
-4
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/IJKPlayerManager.java
...ava/com/shuyu/gsyvideoplayer/player/IJKPlayerManager.java
+5
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/IPlayerManager.java
.../java/com/shuyu/gsyvideoplayer/player/IPlayerManager.java
+1
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/SystemPlayerManager.java
.../com/shuyu/gsyvideoplayer/player/SystemPlayerManager.java
+5
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYVideoControlView.java
.../shuyu/gsyvideoplayer/video/base/GSYVideoControlView.java
+3
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYVideoViewBridge.java
...m/shuyu/gsyvideoplayer/video/base/GSYVideoViewBridge.java
+2
-0
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/ExoHelper.java
...o2/src/main/java/tv/danmaku/ijk/media/exo2/ExoHelper.java
+13
-9
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java
...in/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java
+37
-38
未找到文件。
README.md
浏览文件 @
0284d70e
...
...
@@ -132,7 +132,7 @@ compile 'com.shuyu:gsyVideoPlayer-ex_so:4.1.3'
## 五、近期版本
### 5.0.0(2018-XX-XX)
*
调整cache机制,抽离cache管理器
*
调整cache机制,抽离cache管理器
。
*
update ExoPlayer to 2.8.0,全面针对ExoPlayer进行优化
*
优化ExoPlayer的问题
*
增加ExoPlayer循环播放支持
...
...
app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java
浏览文件 @
0284d70e
...
...
@@ -30,7 +30,7 @@ public class GSYApplication extends Application {
//GSYVideoType.enableMediaCodecTexture();
//GSYVideoManager.instance().setVideoType(this, GSYVideoType.IJKEXOPLAYER); //EXO 1 播放内核,弃用
//
GSYVideoManager.instance().setVideoType(this, GSYVideoType.IJKEXOPLAYER2); //EXO 2 播放内核
GSYVideoManager
.
instance
().
setVideoType
(
this
,
GSYVideoType
.
IJKEXOPLAYER2
);
//EXO 2 播放内核
//GSYVideoManager.instance().setVideoType(this, GSYVideoType.SYSTEMPLAYER); //系统播放器
//GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);
...
...
app/src/main/java/com/example/gsyvideoplayer/adapter/ListNormalAdapter.java
浏览文件 @
0284d70e
...
...
@@ -98,13 +98,13 @@ public class ListNormalAdapter extends BaseAdapter {
//默认缓存路径
//使用lazy的set可以避免滑动卡的情况存在
//holder.gsyVideoPlayer.setUpLazy(url, fals
e, null, null, "这是title");
holder
.
gsyVideoPlayer
.
setUpLazy
(
url
,
tru
e
,
null
,
null
,
"这是title"
);
//holder.gsyVideoPlayer.setNeedShowWifiTip(false);
/************************下方为其他路径************************************/
//如果一个列表的缓存路劲都一一致
holder
.
gsyVideoPlayer
.
setUp
(
url
,
true
,
new
File
(
FileUtils
.
getTestPath
()),
"这是title"
);
//
holder.gsyVideoPlayer.setUp(url, true, new File(FileUtils.getTestPath()), "这是title");
/************************下方为其他路径************************************/
//如果一个列表里的缓存路劲不一致
...
...
app/src/main/java/com/example/gsyvideoplayer/exo/GSYExoPlayerManager.java
浏览文件 @
0284d70e
...
...
@@ -89,7 +89,10 @@ public class GSYExoPlayerManager implements IPlayerManager {
@Override
public
void
releaseSurface
()
{
if
(
surface
!=
null
)
{
surface
.
release
();
surface
=
null
;
}
}
@Override
...
...
@@ -104,6 +107,10 @@ public class GSYExoPlayerManager implements IPlayerManager {
}
}
@Override
public
int
getBufferedPercentage
()
{
return
-
1
;
}
/**
* 上一集
...
...
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoBaseManager.java
浏览文件 @
0284d70e
...
...
@@ -433,6 +433,15 @@ public abstract class GSYVideoBaseManager implements IMediaPlayer.OnPreparedList
clearDefaultCache
(
context
,
url
);
}
@Override
public
int
getBufferedPercentage
()
{
if
(
playerManager
!=
null
)
{
return
playerManager
.
getBufferedPercentage
();
}
return
0
;
}
protected
void
sendMessage
(
Message
message
)
{
mMediaHandler
.
sendMessage
(
message
);
}
...
...
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/EXO2PlayerManager.java
浏览文件 @
0284d70e
...
...
@@ -46,10 +46,11 @@ public class EXO2PlayerManager implements IPlayerManager {
try
{
mediaPlayer
.
setLooping
(
gsyModel
.
isLooping
());
mediaPlayer
.
setCache
(
gsyModel
.
isCache
());
mediaPlayer
.
setCacheDir
(
gsyModel
.
getCachePath
());
mediaPlayer
.
setDataSource
(
context
,
Uri
.
parse
(
gsyModel
.
getUrl
()),
gsyModel
.
getMapHeadData
());
//很遗憾,EXO2的setSpeed只能在播放前生效
if
(
gsyModel
.
getSpeed
()
!=
1
&&
gsyModel
.
getSpeed
()
>
0
)
{
mediaPlayer
.
setSpeed
(
gsyModel
.
getSpeed
(),
1
);
mediaPlayer
.
setSpeed
(
gsyModel
.
getSpeed
(),
1
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -83,7 +84,7 @@ public class EXO2PlayerManager implements IPlayerManager {
@Override
public
void
setNeedMute
(
boolean
needMute
)
{
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
if
(
needMute
)
{
mediaPlayer
.
setVolume
(
0
,
0
);
}
else
{
...
...
@@ -95,7 +96,7 @@ public class EXO2PlayerManager implements IPlayerManager {
@Override
public
void
releaseSurface
()
{
if
(
surface
!=
null
)
{
if
(
surface
!=
null
)
{
surface
.
release
();
surface
=
null
;
}
...
...
@@ -103,7 +104,7 @@ public class EXO2PlayerManager implements IPlayerManager {
@Override
public
void
release
()
{
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
setSurface
(
null
);
mediaPlayer
.
release
();
}
...
...
@@ -112,4 +113,12 @@ public class EXO2PlayerManager implements IPlayerManager {
dummySurface
=
null
;
}
}
@Override
public
int
getBufferedPercentage
()
{
if
(
mediaPlayer
!=
null
)
{
return
mediaPlayer
.
getBufferedPercentage
();
}
return
0
;
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/IJKPlayerManager.java
浏览文件 @
0284d70e
...
...
@@ -165,6 +165,11 @@ public class IJKPlayerManager implements IPlayerManager {
}
}
@Override
public
int
getBufferedPercentage
()
{
return
-
1
;
}
private
void
initIJKOption
(
IjkMediaPlayer
ijkMediaPlayer
,
List
<
VideoOptionModel
>
optionModelList
)
{
if
(
optionModelList
!=
null
&&
optionModelList
.
size
()
>
0
)
{
for
(
VideoOptionModel
videoOptionModel
:
optionModelList
)
{
...
...
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/IPlayerManager.java
浏览文件 @
0284d70e
...
...
@@ -31,4 +31,5 @@ public interface IPlayerManager {
void
release
();
int
getBufferedPercentage
();
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/player/SystemPlayerManager.java
浏览文件 @
0284d70e
...
...
@@ -104,4 +104,9 @@ public class SystemPlayerManager implements IPlayerManager {
mediaPlayer
.
release
();
}
}
@Override
public
int
getBufferedPercentage
()
{
return
-
1
;
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYVideoControlView.java
浏览文件 @
0284d70e
...
...
@@ -896,6 +896,9 @@ public abstract class GSYVideoControlView extends GSYVideoView implements View.O
if
(!
mTouchingProgressBar
)
{
if
(
progress
!=
0
)
mProgressBar
.
setProgress
(
progress
);
}
if
(
getGSYVideoManager
().
getBufferedPercentage
()
>
0
)
{
secProgress
=
getGSYVideoManager
().
getBufferedPercentage
();
}
if
(
secProgress
>
94
)
secProgress
=
100
;
if
(
secProgress
!=
0
&&
!
getGSYVideoManager
().
isCacheFile
())
{
mProgressBar
.
setSecondaryProgress
(
secProgress
);
...
...
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYVideoViewBridge.java
浏览文件 @
0284d70e
...
...
@@ -37,6 +37,8 @@ public interface GSYVideoViewBridge {
IMediaPlayer
getMediaPlayer
();
int
getBufferedPercentage
();
void
releaseMediaPlayer
();
void
setCurrentVideoHeight
(
int
currentVideoHeight
);
...
...
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/ExoHelper.java
浏览文件 @
0284d70e
...
...
@@ -50,24 +50,24 @@ public class ExoHelper {
}
public
MediaSource
getMediaSource
(
String
dataSource
,
boolean
preview
,
boolean
cacheEnable
,
boolean
isLooping
)
{
public
MediaSource
getMediaSource
(
String
dataSource
,
boolean
preview
,
boolean
cacheEnable
,
boolean
isLooping
,
File
cacheDir
)
{
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
DefaultSsChunkSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
cacheEnable
,
preview
,
cacheDir
)),
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
)),
mediaSource
=
new
DashMediaSource
.
Factory
(
new
DefaultDashChunkSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
cacheEnable
,
preview
,
cacheDir
)),
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
);
mediaSource
=
new
HlsMediaSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
cacheEnable
,
preview
,
cacheDir
)).
createMediaSource
(
contentUri
);
break
;
case
TYPE_RTMP:
RtmpDataSourceFactory
rtmpDataSourceFactory
=
new
RtmpDataSourceFactory
(
null
);
...
...
@@ -77,7 +77,7 @@ public class ExoHelper {
break
;
case
C
.
TYPE_OTHER
:
default
:
mediaSource
=
new
ExtractorMediaSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
dataSource
,
cacheEnable
,
preview
))
mediaSource
=
new
ExtractorMediaSource
.
Factory
(
getDataSourceFactoryCache
(
mAppContext
,
cacheEnable
,
preview
,
cacheDir
))
.
setExtractorsFactory
(
new
DefaultExtractorsFactory
())
.
createMediaSource
(
contentUri
);
break
;
...
...
@@ -109,9 +109,13 @@ public class ExoHelper {
/**
* 本地缓存目录
*/
public
Cache
getCache
(
Context
context
)
{
public
Cache
getCache
(
Context
context
,
File
cacheDir
)
{
String
dirs
=
context
.
getCacheDir
().
getAbsolutePath
();
if
(
cacheDir
!=
null
)
{
dirs
=
cacheDir
.
getAbsolutePath
();
}
if
(
mCache
==
null
)
{
String
path
=
context
.
getCacheDir
().
getAbsolutePath
()
+
File
.
separator
+
"exo"
;
String
path
=
dirs
+
File
.
separator
+
"exo"
;
boolean
isLocked
=
SimpleCache
.
isCacheFolderLocked
(
new
File
(
path
));
if
(!
isLocked
)
{
mCache
=
new
SimpleCache
(
new
File
(
path
),
new
LeastRecentlyUsedCacheEvictor
(
1024
*
1024
*
100
));
...
...
@@ -135,9 +139,9 @@ public class ExoHelper {
/**
* 获取SourceFactory,是否带Cache
*/
private
DataSource
.
Factory
getDataSourceFactoryCache
(
Context
context
,
String
dataSource
,
boolean
cacheEnable
,
boolean
preview
)
{
private
DataSource
.
Factory
getDataSourceFactoryCache
(
Context
context
,
boolean
cacheEnable
,
boolean
preview
,
File
cacheDir
)
{
if
(
cacheEnable
)
{
Cache
cache
=
getCache
(
context
);
Cache
cache
=
getCache
(
context
,
cacheDir
);
return
new
CacheDataSourceFactory
(
cache
,
getDataSourceFactory
(
context
,
preview
),
CacheDataSource
.
FLAG_IGNORE_CACHE_ON_ERROR
);
}
else
{
return
getDataSourceFactory
(
context
,
preview
);
...
...
gsyvideoplayer-exo2/src/main/java/tv/danmaku/ijk/media/exo2/IjkExo2MediaPlayer.java
浏览文件 @
0284d70e
/*
* Copyright (C) 2015 Bilibili
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
tv.danmaku.ijk.media.exo2
;
import
android.content.Context
;
import
android.net.NetworkInfo
;
import
android.net.Uri
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Size
;
import
android.view.Surface
;
...
...
@@ -39,29 +21,17 @@ import com.google.android.exoplayer2.SimpleExoPlayer;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.analytics.AnalyticsListener
;
import
com.google.android.exoplayer2.decoder.DecoderCounters
;
import
com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory
;
import
com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
;
import
com.google.android.exoplayer2.metadata.Metadata
;
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.MediaSourceEventListener
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
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.trackselection.AdaptiveTrackSelection
;
import
com.google.android.exoplayer2.trackselection.DefaultTrackSelector
;
import
com.google.android.exoplayer2.trackselection.TrackSelection
;
import
com.google.android.exoplayer2.trackselection.TrackSelectionArray
;
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.util.Util
;
import
java.io.File
;
import
java.io.FileDescriptor
;
import
java.io.IOException
;
import
java.util.HashMap
;
...
...
@@ -76,8 +46,7 @@ import tv.danmaku.ijk.media.player.misc.IjkTrackInfo;
/**
* Created by guoshuyu on 2018/1/10.
* ExoPlayer2
* fork from https://github.com/DyncKathline/IJKPlayer-android
* Exo
*/
public
class
IjkExo2MediaPlayer
extends
AbstractMediaPlayer
implements
Player
.
EventListener
,
AnalyticsListener
{
private
static
final
String
TAG
=
"IjkExo2MediaPlayer"
;
...
...
@@ -99,9 +68,22 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
private
boolean
mIsPrepareing
=
true
;
private
boolean
mIsBuffering
=
false
;
private
boolean
isLooping
=
false
;
/**
* 是否带上header
*/
private
boolean
isPreview
=
false
;
/**
* 是否开启缓存
*/
private
boolean
isCache
=
false
;
/**
* dataSource等的帮组类
*/
private
ExoHelper
mExoHelper
;
/**
* 缓存目录,可以为空
*/
private
File
mCacheDir
;
private
int
audioSessionId
=
C
.
AUDIO_SESSION_ID_UNSET
;
...
...
@@ -143,11 +125,6 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
}
}
@Override
public
void
setDataSource
(
Context
context
,
Uri
uri
)
{
mDataSource
=
uri
.
toString
();
mMediaSource
=
mExoHelper
.
getMediaSource
(
mDataSource
,
isPreview
,
isCache
,
isLooping
);
}
@Override
public
void
setDataSource
(
Context
context
,
Uri
uri
,
Map
<
String
,
String
>
headers
)
{
...
...
@@ -163,6 +140,12 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
setDataSource
(
mAppContext
,
Uri
.
parse
(
path
));
}
@Override
public
void
setDataSource
(
Context
context
,
Uri
uri
)
{
mDataSource
=
uri
.
toString
();
mMediaSource
=
mExoHelper
.
getMediaSource
(
mDataSource
,
isPreview
,
isCache
,
isLooping
,
mCacheDir
);
}
@Override
public
void
setDataSource
(
FileDescriptor
fd
)
{
throw
new
UnsupportedOperationException
(
"no support"
);
...
...
@@ -374,6 +357,7 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
}
/**
* 是否需要带上header
* setDataSource之前生效
*
* @param preview
...
...
@@ -391,6 +375,7 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
}
/**
* 是否开启cache
* setDataSource之前生效
*
* @param cache
...
...
@@ -399,6 +384,20 @@ public class IjkExo2MediaPlayer extends AbstractMediaPlayer implements Player.Ev
isCache
=
cache
;
}
public
File
getCacheDir
()
{
return
mCacheDir
;
}
/**
* cache文件的目录
* setDataSource之前生效
*
* @param cacheDir
*/
public
void
setCacheDir
(
File
cacheDir
)
{
this
.
mCacheDir
=
cacheDir
;
}
public
MediaSource
getMediaSource
()
{
return
mMediaSource
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录