From c777f89f3929333b0ea8c7eb57fcf250b0ad1372 Mon Sep 17 00:00:00 2001 From: okjackcaptain <378702538@qq.com> Date: Sat, 3 Dec 2022 12:36:34 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E8=AE=BE=E7=BD=AE=E6=96=B0=E5=A2=9EIJK?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=92=AD=E6=94=BE=E5=BC=80=E5=85=B3=EF=BC=8C?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD=20(by=20okjack)=20-=20?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEIJK=E5=8D=95=E4=B8=AA=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=99=90=E5=88=B660M=20(by=20okjack)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tvbox/osc/player/IjkMediaPlayer.java | 32 ++- .../osc/ui/fragment/ModelSettingFragment.java | 37 +-- .../com/github/tvbox/osc/util/HawkConfig.java | 1 + app/src/main/res/layout/fragment_model.xml | 257 +++++++++++------- 4 files changed, 195 insertions(+), 132 deletions(-) diff --git a/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java b/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java index 2962d7c3..9fed9b43 100644 --- a/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java +++ b/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java @@ -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; @@ -62,20 +64,22 @@ public class IjkMediaPlayer extends IjkPlayer { } 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(); - String tmpMd5 = MD5.string2MD5(path); - cachePath += tmpMd5 + ".file"; - cacheMapPath += tmpMd5 + ".map"; - mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "cache_file_path", cachePath); - 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; + if (Hawk.get(HawkConfig.IJK_CACHE_PLAY, false)) { + String cachePath = FileUtils.getCachePath() + "/ijkcaches/"; + String cacheMapPath = cachePath; + File cacheFile = new File(cachePath); + if (!cacheFile.exists()) cacheFile.mkdirs(); + String tmpMd5 = MD5.string2MD5(path); + cachePath += tmpMd5 + ".file"; + cacheMapPath += tmpMd5 + ".map"; + mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "cache_file_path", cachePath); + 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", 60 * 1024 * 1024); + mMediaPlayer.setOption(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_FORMAT, "cache_file_forwards_capacity", 6 * 1024 * 1024); + path = "ijkio:cache:ffio:" + path; + } } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java b/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java index 733a7d0e..b118ce92 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java @@ -71,6 +71,7 @@ public class ModelSettingFragment extends BaseLazyFragment { private TextView tvShowPreviewText; private TextView tvFastSearchText; private TextView tvRecStyleText; + private TextView tvIjkCachePlay; public static ModelSettingFragment newInstance() { return new ModelSettingFragment().setArguments(); @@ -105,6 +106,7 @@ public class ModelSettingFragment extends BaseLazyFragment { tvHomeRec = findViewById(R.id.tvHomeRec); tvHistoryNum = findViewById(R.id.tvHistoryNum); tvSearchView = findViewById(R.id.tvSearchView); + tvIjkCachePlay = findViewById(R.id.tvIjkCachePlay); tvMediaCodec.setText(Hawk.get(HawkConfig.IJK_CODEC, "")); tvDebugOpen.setText(Hawk.get(HawkConfig.DEBUG_OPEN, false) ? "已打开" : "已关闭"); tvParseWebView.setText(Hawk.get(HawkConfig.PARSE_WEBVIEW, true) ? "系统自带" : "XWalkView"); @@ -118,6 +120,7 @@ public class ModelSettingFragment extends BaseLazyFragment { tvScale.setText(PlayerHelper.getScaleName(Hawk.get(HawkConfig.PLAY_SCALE, 0))); tvPlay.setText(PlayerHelper.getPlayerName(Hawk.get(HawkConfig.PLAY_TYPE, 0))); tvRender.setText(PlayerHelper.getRenderName(Hawk.get(HawkConfig.PLAY_RENDER, 0))); + tvIjkCachePlay.setText(Hawk.get(HawkConfig.IJK_CACHE_PLAY, false) ? "开启" : "关闭"); findViewById(R.id.llDebug).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -656,31 +659,29 @@ public class ModelSettingFragment extends BaseLazyFragment { } }); + findViewById(R.id.llIjkCachePlay).setOnClickListener((view -> onClickIjkCachePlay(view))); findViewById(R.id.llClearCache).setOnClickListener((view -> onClickClearCache(view))); } + private void onClickIjkCachePlay(View v) { + FastClickCheckUtil.check(v); + Hawk.put(HawkConfig.IJK_CACHE_PLAY, !Hawk.get(HawkConfig.IJK_CACHE_PLAY, false)); + tvIjkCachePlay.setText(Hawk.get(HawkConfig.IJK_CACHE_PLAY, false) ? "开启" : "关闭"); + } + private void onClickClearCache(View v) { FastClickCheckUtil.check(v); String cachePath = FileUtils.getCachePath(); File cacheDir = new File(cachePath); - if (!cacheDir.exists()) { - Toast.makeText(getContext(), "暂无缓存", Toast.LENGTH_LONG).show(); - return; - } - try { - new Thread(() -> { - try { - FileUtils.cleanDirectory(cacheDir); - } catch (Exception e) { - e.printStackTrace(); - } - }).start(); - Toast.makeText(getContext(), "缓存已清空", Toast.LENGTH_LONG).show(); - return; - } catch (Exception e) { - e.printStackTrace(); - } - Toast.makeText(getContext(), "缓存清空出错", Toast.LENGTH_LONG).show(); + if (!cacheDir.exists()) return; + new Thread(() -> { + try { + FileUtils.cleanDirectory(cacheDir); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + Toast.makeText(getContext(), "缓存已清空", Toast.LENGTH_LONG).show(); return; } diff --git a/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java b/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java index 0adc0910..904a79b5 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java +++ b/app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java @@ -37,4 +37,5 @@ public class HawkConfig { public static final String HOME_REC_STYLE = "home_rec_style"; public static final String NOW_DATE = "now_date"; //当前日期 public static final String REMOTE_TVBOX = "remote_tvbox_host"; + public static final String IJK_CACHE_PLAY = "ijk_cache_play"; } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_model.xml b/app/src/main/res/layout/fragment_model.xml index fb12ac35..5520c6b9 100644 --- a/app/src/main/res/layout/fragment_model.xml +++ b/app/src/main/res/layout/fragment_model.xml @@ -882,133 +882,190 @@ - - - + android:focusable="false" + android:orientation="horizontal"> - - + - + + + + + + + + + + + + + + + + + + + android:layout_marginBottom="@dimen/vs_10" + android:focusable="false" + android:orientation="horizontal"> - + - + - - - + - + + - + - + + + + + + + - -