Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ac13
GSYVideoPlayer
提交
4be27cdd
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 搜索 >>
提交
4be27cdd
编写于
11月 30, 2016
作者:
S
shuyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.3.4 清除缓存接口
上级
9457dcdf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
206 addition
and
15 deletion
+206
-15
README.md
README.md
+26
-0
app/src/main/java/com/example/gsyvideoplayer/MainActivity.java
...rc/main/java/com/example/gsyvideoplayer/MainActivity.java
+7
-1
app/src/main/java/com/example/gsyvideoplayer/PlayActivity.java
...rc/main/java/com/example/gsyvideoplayer/PlayActivity.java
+2
-2
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_main.xml
+7
-0
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoManager.java
...c/main/java/com/shuyu/gsyvideoplayer/GSYVideoManager.java
+30
-1
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoPlayer.java
...rc/main/java/com/shuyu/gsyvideoplayer/GSYVideoPlayer.java
+41
-11
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/utils/FileUtils.java
...c/main/java/com/shuyu/gsyvideoplayer/utils/FileUtils.java
+15
-0
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/utils/StorageUtils.java
...ain/java/com/shuyu/gsyvideoplayer/utils/StorageUtils.java
+78
-0
未找到文件。
README.md
浏览文件 @
4be27cdd
...
@@ -45,6 +45,32 @@ compile 'com.shuyu:gsyVideoPlayer:1.3.3'
...
@@ -45,6 +45,32 @@ compile 'com.shuyu:gsyVideoPlayer:1.3.3'
*
<h4>
3、详情模式
</h4>
*
<h4>
3、详情模式
</h4>
<img
src=
"https://github.com/CarGuo/GSYVideoPlayer/blob/master/04.gif"
width=
"240px"
height=
"426px"
/>
<img
src=
"https://github.com/CarGuo/GSYVideoPlayer/blob/master/04.gif"
width=
"240px"
height=
"426px"
/>
### 1.3.4 增加了清除默认缓存接口,优化了临时缓存文件错误的清理
GSYVideoManager
```
/**
* 删除默认所有缓存文件
*/
public static void clearAllDefaultCache(Context context)
/**
* 删除url对应默认缓存文件
*/
public static void clearDefaultCache(Context context, String url)
```
GSYVideoPlayer
```
/**
* 清除当前缓存
*/
public void clearCurrentCache()
```
### 1.3.3 优化了一些内存泄漏问题,更新了demo
### 1.3.3 优化了一些内存泄漏问题,更新了demo
...
...
app/src/main/java/com/example/gsyvideoplayer/MainActivity.java
浏览文件 @
4be27cdd
...
@@ -6,6 +6,7 @@ import android.view.View;
...
@@ -6,6 +6,7 @@ import android.view.View;
import
android.widget.Button
;
import
android.widget.Button
;
import
com.example.gsyvideoplayer.utils.JumpUtils
;
import
com.example.gsyvideoplayer.utils.JumpUtils
;
import
com.shuyu.gsyvideoplayer.GSYVideoManager
;
import
com.shuyu.gsyvideoplayer.utils.Debuger
;
import
com.shuyu.gsyvideoplayer.utils.Debuger
;
import
butterknife.BindView
;
import
butterknife.BindView
;
...
@@ -25,7 +26,7 @@ public class MainActivity extends AppCompatActivity {
...
@@ -25,7 +26,7 @@ public class MainActivity extends AppCompatActivity {
ButterKnife
.
bind
(
this
);
ButterKnife
.
bind
(
this
);
}
}
@OnClick
({
R
.
id
.
open_btn
,
R
.
id
.
list_btn
,
R
.
id
.
list_btn_2
,
R
.
id
.
list_detail
})
@OnClick
({
R
.
id
.
open_btn
,
R
.
id
.
list_btn
,
R
.
id
.
list_btn_2
,
R
.
id
.
list_detail
,
R
.
id
.
clear_cache
})
public
void
onClick
(
View
view
)
{
public
void
onClick
(
View
view
)
{
switch
(
view
.
getId
())
{
switch
(
view
.
getId
())
{
case
R
.
id
.
open_btn
:
case
R
.
id
.
open_btn
:
...
@@ -44,6 +45,11 @@ public class MainActivity extends AppCompatActivity {
...
@@ -44,6 +45,11 @@ public class MainActivity extends AppCompatActivity {
//支持全屏重力旋转的列表播放,滑动后不会被销毁
//支持全屏重力旋转的列表播放,滑动后不会被销毁
JumpUtils
.
goToDetailPlayer
(
this
);
JumpUtils
.
goToDetailPlayer
(
this
);
break
;
break
;
case
R
.
id
.
clear_cache
:
GSYVideoManager
.
clearAllDefaultCache
(
MainActivity
.
this
);
//String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
//GSYVideoManager.clearDefaultCache(MainActivity.this, url);
break
;
}
}
}
}
}
}
app/src/main/java/com/example/gsyvideoplayer/PlayActivity.java
浏览文件 @
4be27cdd
...
@@ -52,8 +52,8 @@ public class PlayActivity extends AppCompatActivity {
...
@@ -52,8 +52,8 @@ public class PlayActivity extends AppCompatActivity {
private
void
init
()
{
private
void
init
()
{
String
url
=
"http://baobab.wdjcdn.com/14564977406580.mp4"
;
String
url
=
"http://baobab.wdjcdn.com/14564977406580.mp4"
;
//需要路径的
//需要路径的
videoPlayer
.
setUp
(
url
,
true
,
new
File
(
FileUtils
.
getPath
()),
""
);
//
videoPlayer.setUp(url, true, new File(FileUtils.getPath()), "");
//
videoPlayer.setUp(url, true, "");
videoPlayer
.
setUp
(
url
,
true
,
""
);
//增加封面
//增加封面
ImageView
imageView
=
new
ImageView
(
this
);
ImageView
imageView
=
new
ImageView
(
this
);
...
...
app/src/main/res/layout/activity_main.xml
浏览文件 @
4be27cdd
...
@@ -38,4 +38,11 @@
...
@@ -38,4 +38,11 @@
android:layout_marginTop=
"20dp"
android:layout_marginTop=
"20dp"
android:text=
"Detail Video2"
/>
android:text=
"Detail Video2"
/>
<Button
android:id=
"@+id/clear_cache"
android:layout_width=
"120dp"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"20dp"
android:text=
"clear Cache"
/>
</LinearLayout>
</LinearLayout>
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoManager.java
浏览文件 @
4be27cdd
...
@@ -11,8 +11,12 @@ import android.text.TextUtils;
...
@@ -11,8 +11,12 @@ import android.text.TextUtils;
import
android.view.Surface
;
import
android.view.Surface
;
import
com.danikula.videocache.HttpProxyCacheServer
;
import
com.danikula.videocache.HttpProxyCacheServer
;
import
com.danikula.videocache.file.Md5FileNameGenerator
;
import
com.shuyu.gsyvideoplayer.listener.GSYMediaPlayerListener
;
import
com.shuyu.gsyvideoplayer.listener.GSYMediaPlayerListener
;
import
com.shuyu.gsyvideoplayer.model.GSYModel
;
import
com.shuyu.gsyvideoplayer.model.GSYModel
;
import
com.shuyu.gsyvideoplayer.utils.CommonUtil
;
import
com.shuyu.gsyvideoplayer.utils.FileUtils
;
import
com.shuyu.gsyvideoplayer.utils.StorageUtils
;
import
java.io.File
;
import
java.io.File
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
...
@@ -76,6 +80,32 @@ public class GSYVideoManager implements IMediaPlayer.OnPreparedListener, IMediaP
...
@@ -76,6 +80,32 @@ public class GSYVideoManager implements IMediaPlayer.OnPreparedListener, IMediaP
GSYVideoManager
.
instance
().
newProxy
(
context
))
:
proxy
;
GSYVideoManager
.
instance
().
newProxy
(
context
))
:
proxy
;
}
}
/**
* 删除默认所有缓存文件
*/
public
static
void
clearAllDefaultCache
(
Context
context
)
{
String
path
=
StorageUtils
.
getIndividualCacheDirectory
(
context
.
getApplicationContext
()).
getAbsolutePath
();
FileUtils
.
deleteFiles
(
new
File
(
path
));
}
/**
* 删除url对应默认缓存文件
*/
public
static
void
clearDefaultCache
(
Context
context
,
String
url
)
{
Md5FileNameGenerator
md5FileNameGenerator
=
new
Md5FileNameGenerator
();
String
name
=
md5FileNameGenerator
.
generate
(
url
);
String
pathTmp
=
StorageUtils
.
getIndividualCacheDirectory
(
context
.
getApplicationContext
()).
getAbsolutePath
()
+
File
.
separator
+
name
+
".download"
;
String
path
=
StorageUtils
.
getIndividualCacheDirectory
(
context
.
getApplicationContext
()).
getAbsolutePath
()
+
File
.
separator
+
name
;
CommonUtil
.
deleteFile
(
pathTmp
);
CommonUtil
.
deleteFile
(
path
);
}
/**
/**
* 获取缓存代理服务,带文件目录的
* 获取缓存代理服务,带文件目录的
*/
*/
...
@@ -107,7 +137,6 @@ public class GSYVideoManager implements IMediaPlayer.OnPreparedListener, IMediaP
...
@@ -107,7 +137,6 @@ public class GSYVideoManager implements IMediaPlayer.OnPreparedListener, IMediaP
}
}
}
}
/**
/**
* 创建缓存代理服务,带文件目录的.
* 创建缓存代理服务,带文件目录的.
*/
*/
...
...
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoPlayer.java
浏览文件 @
4be27cdd
...
@@ -23,8 +23,10 @@ import android.widget.TextView;
...
@@ -23,8 +23,10 @@ import android.widget.TextView;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.danikula.videocache.HttpProxyCacheServer
;
import
com.danikula.videocache.HttpProxyCacheServer
;
import
com.danikula.videocache.file.Md5FileNameGenerator
;
import
com.shuyu.gsyvideoplayer.utils.CommonUtil
;
import
com.shuyu.gsyvideoplayer.utils.CommonUtil
;
import
com.shuyu.gsyvideoplayer.utils.Debuger
;
import
com.shuyu.gsyvideoplayer.utils.Debuger
;
import
com.shuyu.gsyvideoplayer.utils.StorageUtils
;
import
com.shuyu.gsyvideoplayer.video.GSYBaseVideoPlayer
;
import
com.shuyu.gsyvideoplayer.video.GSYBaseVideoPlayer
;
import
java.io.File
;
import
java.io.File
;
...
@@ -715,7 +717,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
...
@@ -715,7 +717,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
mTextureViewContainer
.
removeAllViews
();
mTextureViewContainer
.
removeAllViews
();
}
}
if
(
IF_FULLSCREEN_FROM_NORMAL
)
{
//如果在进入全屏后播放完就初始化自己非全屏的控件
if
(
IF_FULLSCREEN_FROM_NORMAL
)
{
IF_FULLSCREEN_FROM_NORMAL
=
false
;
IF_FULLSCREEN_FROM_NORMAL
=
false
;
if
(
GSYVideoManager
.
instance
().
lastListener
()
!=
null
)
{
if
(
GSYVideoManager
.
instance
().
lastListener
()
!=
null
)
{
GSYVideoManager
.
instance
().
lastListener
().
onAutoCompletion
();
GSYVideoManager
.
instance
().
lastListener
().
onAutoCompletion
();
...
@@ -773,16 +775,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
...
@@ -773,16 +775,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
public
void
onError
(
int
what
,
int
extra
)
{
public
void
onError
(
int
what
,
int
extra
)
{
if
(
what
!=
38
&&
what
!=
-
38
)
{
if
(
what
!=
38
&&
what
!=
-
38
)
{
setStateAndUi
(
CURRENT_STATE_ERROR
);
setStateAndUi
(
CURRENT_STATE_ERROR
);
if
(
mCacheFile
)
{
deleteCacheFileWhenError
();
Debuger
.
printfError
(
" mCacheFile Local Error "
+
mUrl
);
//可能是因为缓存文件除了问题
CommonUtil
.
deleteFile
(
mUrl
.
replace
(
"file://"
,
""
));
mUrl
=
mOriginUrl
;
}
else
if
(
mUrl
.
contains
(
"127.0.0.1"
))
{
Debuger
.
printfError
(
" mCacheFile Download Error "
+
mUrl
);
CommonUtil
.
deleteFile
(
mUrl
.
replace
(
"file://"
,
""
)
+
".downlad"
);
mUrl
=
mOriginUrl
;
}
}
}
}
}
...
@@ -825,6 +818,43 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
...
@@ -825,6 +818,43 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
}
}
/**
* 清除当前缓存
*/
public
void
clearCurrentCache
()
{
if
(
mCacheFile
)
{
//是否为缓存文件
Debuger
.
printfError
(
" mCacheFile Local Error "
+
mUrl
);
//可能是因为缓存文件除了问题
CommonUtil
.
deleteFile
(
mUrl
.
replace
(
"file://"
,
""
));
mUrl
=
mOriginUrl
;
}
else
if
(
mUrl
.
contains
(
"127.0.0.1"
))
{
//是否为缓存了未完成的文件
Md5FileNameGenerator
md5FileNameGenerator
=
new
Md5FileNameGenerator
();
String
name
=
md5FileNameGenerator
.
generate
(
mOriginUrl
);
if
(
mCachePath
!=
null
)
{
String
path
=
mCachePath
.
getAbsolutePath
()
+
File
.
separator
+
name
+
".download"
;
CommonUtil
.
deleteFile
(
path
);
}
else
{
String
path
=
StorageUtils
.
getIndividualCacheDirectory
(
getContext
().
getApplicationContext
()).
getAbsolutePath
()
+
File
.
separator
+
name
+
".download"
;
CommonUtil
.
deleteFile
(
path
);
}
}
}
/**
* 播放错误的时候,删除缓存文件
*/
private
void
deleteCacheFileWhenError
()
{
clearCurrentCache
();
Debuger
.
printfError
(
"Link Or mCache Error, Please Try Again"
+
mUrl
);
mUrl
=
mOriginUrl
;
}
protected
void
startProgressTimer
()
{
protected
void
startProgressTimer
()
{
cancelProgressTimer
();
cancelProgressTimer
();
UPDATE_PROGRESS_TIMER
=
new
Timer
();
UPDATE_PROGRESS_TIMER
=
new
Timer
();
...
...
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/utils/FileUtils.java
浏览文件 @
4be27cdd
...
@@ -30,4 +30,19 @@ public class FileUtils {
...
@@ -30,4 +30,19 @@ public class FileUtils {
return
getAppPath
(
NAME_TEST
);
return
getAppPath
(
NAME_TEST
);
}
}
public
static
void
deleteFiles
(
File
root
)
{
File
files
[]
=
root
.
listFiles
();
if
(
files
!=
null
)
{
for
(
File
f
:
files
)
{
if
(!
f
.
isDirectory
()
&&
f
.
exists
())
{
// 判断是否存在
try
{
f
.
delete
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
}
}
\ No newline at end of file
gsyVideoPlayer/src/main/java/com/shuyu/gsyvideoplayer/utils/StorageUtils.java
0 → 100644
浏览文件 @
4be27cdd
package
com.shuyu.gsyvideoplayer.utils
;
import
android.content.Context
;
import
android.os.Environment
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
static
android
.
os
.
Environment
.
MEDIA_MOUNTED
;
/**
* 拷贝了一个videocache中一样的缓存路径
*/
public
class
StorageUtils
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
"StorageUtils"
);
private
static
final
String
INDIVIDUAL_DIR_NAME
=
"video-cache"
;
/**
* Returns individual application cache directory (for only video caching from Proxy). Cache directory will be
* created on SD card <i>("/Android/data/[app_package_name]/cache/video-cache")</i> if card is mounted .
* Else - Android defines cache directory on device's file system.
*
* @param context Application context
* @return Cache {@link File directory}
*/
public
static
File
getIndividualCacheDirectory
(
Context
context
)
{
File
cacheDir
=
getCacheDirectory
(
context
,
true
);
return
new
File
(
cacheDir
,
INDIVIDUAL_DIR_NAME
);
}
/**
* Returns application cache directory. Cache directory will be created on SD card
* <i>("/Android/data/[app_package_name]/cache")</i> (if card is mounted and app has appropriate permission) or
* on device's file system depending incoming parameters.
*
* @param context Application context
* @param preferExternal Whether prefer external location for cache
* @return Cache {@link File directory}.<br />
* <b>NOTE:</b> Can be null in some unpredictable cases (if SD card is unmounted and
* {@link android.content.Context#getCacheDir() Context.getCacheDir()} returns null).
*/
private
static
File
getCacheDirectory
(
Context
context
,
boolean
preferExternal
)
{
File
appCacheDir
=
null
;
String
externalStorageState
;
try
{
externalStorageState
=
Environment
.
getExternalStorageState
();
}
catch
(
NullPointerException
e
)
{
// (sh)it happens
externalStorageState
=
""
;
}
if
(
preferExternal
&&
MEDIA_MOUNTED
.
equals
(
externalStorageState
))
{
appCacheDir
=
getExternalCacheDir
(
context
);
}
if
(
appCacheDir
==
null
)
{
appCacheDir
=
context
.
getCacheDir
();
}
if
(
appCacheDir
==
null
)
{
String
cacheDirPath
=
"/data/data/"
+
context
.
getPackageName
()
+
"/cache/"
;
LOG
.
warn
(
"Can't define system cache directory! '"
+
cacheDirPath
+
"%s' will be used."
);
appCacheDir
=
new
File
(
cacheDirPath
);
}
return
appCacheDir
;
}
private
static
File
getExternalCacheDir
(
Context
context
)
{
File
dataDir
=
new
File
(
new
File
(
Environment
.
getExternalStorageDirectory
(),
"Android"
),
"data"
);
File
appCacheDir
=
new
File
(
new
File
(
dataDir
,
context
.
getPackageName
()),
"cache"
);
if
(!
appCacheDir
.
exists
())
{
if
(!
appCacheDir
.
mkdirs
())
{
LOG
.
warn
(
"Unable to create external cache directory"
);
return
null
;
}
}
return
appCacheDir
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录