- 设置新增IJK缓存播放开关,默认关闭 (by okjack)

- 设置IJK单个缓存限制60M (by okjack)
pull/87/merge
okjackcaptain 3 years ago
parent 837de7ce5d
commit c777f89f39
  1. 32
      app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java
  2. 37
      app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java
  3. 1
      app/src/main/java/com/github/tvbox/osc/util/HawkConfig.java
  4. 257
      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;
@ -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();

@ -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;
}

@ -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";
}

@ -882,133 +882,190 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/vs_60"
android:layout_marginBottom="@dimen/vs_10"
android:focusable="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginEnd="@dimen/vs_5"
android:layout_marginRight="@dimen/vs_5"
android:layout_width="match_parent"
android:layout_height="@dimen/vs_60"
android:layout_marginBottom="@dimen/vs_10"
android:focusable="false"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/llBackup"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginEnd="@dimen/vs_5"
android:layout_marginRight="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
android:focusable="false"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="数据备份还原"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/llIjkCachePlay"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/vs_5"
android:layout_marginRight="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IJK缓存"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tvIjkCachePlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="关闭"
android:textSize="@dimen/ts_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
</LinearLayout>
<LinearLayout
android:id="@+id/llClearCache"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/vs_5"
android:layout_marginLeft="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清空缓存"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/llClearCache"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_height="@dimen/vs_60"
android:layout_weight="1"
android:layout_marginStart="@dimen/vs_5"
android:layout_marginLeft="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
android:layout_marginBottom="@dimen/vs_10"
android:focusable="false"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清空缓存"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<LinearLayout
android:id="@+id/llBackup"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/vs_5"
android:layout_marginRight="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="数据备份还原"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/llAbout"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/vs_5"
android:layout_marginLeft="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="关于"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<LinearLayout
android:id="@+id/llAbout"
android:layout_width="@dimen/vs_0"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/vs_5"
android:layout_marginLeft="@dimen/vs_5"
android:layout_weight="1"
android:background="@drawable/shape_setting_model_focus"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/vs_20"
android:paddingRight="@dimen/vs_20">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="关于"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_24" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/vs_10"
android:layout_marginLeft="@dimen/vs_10"
android:text=">"
android:textColor="@android:color/white"
android:textSize="@dimen/ts_30" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

Loading…
Cancel
Save