- 限制IJK单个播放文件缓存最大容量 (by okjack)

- 设置中清除缓存选项,包括磁力 (by okjack)
pull/87/merge
okjackcaptain 3 years ago
parent b54626d994
commit f3b8e3e074
  1. 10
      app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java
  2. 33
      app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java
  3. 12
      app/src/main/java/com/github/tvbox/osc/util/FileUtils.java
  4. 4
      app/src/main/res/layout/fragment_model.xml

@ -6,7 +6,9 @@ import android.text.TextUtils;
import com.github.tvbox.osc.api.ApiConfig;
import com.github.tvbox.osc.bean.IJKCode;
import com.github.tvbox.osc.util.FileUtils;
import com.github.tvbox.osc.util.HawkConfig;
import com.github.tvbox.osc.util.MD5;
import com.orhanobut.hawk.Hawk;
import java.io.File;
import java.util.LinkedHashMap;
@ -59,8 +61,10 @@ public class IjkMediaPlayer extends IjkPlayer {
mMediaPlayer.setOption(1, "infbuf", 1);
mMediaPlayer.setOption(1, "rtsp_transport", "tcp");
mMediaPlayer.setOption(1, "rtsp_flags", "prefer_tcp");
} else if (!TextUtils.isEmpty(path) && !path.contains(".m3u8") && (path.contains(".mp4") || path.contains(".mkv") || path.contains(".avi"))) {
String cachePath = FileUtils.getExternalCachePath() + "/ijkcaches/";
} else if (!TextUtils.isEmpty(path)
&& !path.contains(".m3u8")
&& (path.contains(".mp4") || path.contains(".mkv") || path.contains(".avi"))) {
String cachePath = FileUtils.getCachePath() + "/ijkcaches/";
String cacheMapPath = cachePath;
File cacheFile = new File(cachePath);
if (!cacheFile.exists()) cacheFile.mkdirs();
@ -71,6 +75,8 @@ public class IjkMediaPlayer extends IjkPlayer {
mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "cache_map_path", cacheMapPath);
mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "parse_cache_map", 1);
mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "auto_save_map", 1);
mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "cache_max_capacity", 100 * 1024 * 1024);
mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "cache_file_forwards_capacity", 20 * 1024 * 1024);
path = "ijkio:cache:ffio:" + path;
}
} catch (Exception e) {

@ -656,27 +656,26 @@ public class ModelSettingFragment extends BaseLazyFragment {
}
});
findViewById(R.id.llClearIjkCache).setOnClickListener((view -> onClickClearIjkCache()));
findViewById(R.id.llClearCache).setOnClickListener((view -> onClickClearCache(view)));
}
private void onClickClearIjkCache() {
String cachePath = FileUtils.getExternalCachePath() + "/ijkcaches/";
private void onClickClearCache(View v) {
FastClickCheckUtil.check(v);
String cachePath = FileUtils.getCachePath();
File cacheDir = new File(cachePath);
if (!cacheDir.exists()) return;
File[] files = cacheDir.listFiles();
if (files != null && files.length > 0) {
try {
for(File one : files) {
LOG.i("ijkplayer cache:" + one.getAbsolutePath());
one.delete();
}
Toast.makeText(getContext(), "ijk缓存已清空", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(getContext(), "暂无ijk缓存", Toast.LENGTH_LONG).show();
if (!cacheDir.exists()) {
Toast.makeText(getContext(), "暂无缓存", Toast.LENGTH_LONG).show();
return;
}
try {
FileUtils.cleanDirectory(cacheDir);
Toast.makeText(getContext(), "缓存已清空", Toast.LENGTH_LONG).show();
return;
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(getContext(), "缓存清空出错", Toast.LENGTH_LONG).show();
return;
}

@ -125,12 +125,16 @@ public class FileUtils {
return new File(path.replace("file:/", getRootPath()));
}
public static File getExternalCacheDir() {
return App.getInstance().getExternalCacheDir();
public static File getCacheDir() {
return App.getInstance().getCacheDir();
}
public static String getExternalCachePath() {
return getExternalCacheDir().getAbsolutePath();
public static String getCachePath() {
return getCacheDir().getAbsolutePath();
}
public static void cleanDirectory(File dir) throws IOException {
org.apache.commons.io.FileUtils.cleanDirectory(dir);
}
public static String read(String path) {

@ -937,7 +937,7 @@
<LinearLayout
android:id="@+id/llClearIjkCache"
android:id="@+id/llClearCache"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/vs_5"
@ -953,7 +953,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清空IJK缓存"
android:text="清空缓存"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />

Loading…
Cancel
Save