pull/212/head
FongMi 2 years ago
parent c0e3ed2d54
commit 6001d484dc
  1. 16
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  2. 18
      app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java
  3. 4
      catvod/src/main/java/com/github/catvod/net/interceptor/DefaultInterceptor.java

@ -134,6 +134,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
private List<String> mBroken; private List<String> mBroken;
private History mHistory; private History mHistory;
private Players mPlayers; private Players mPlayers;
private boolean background;
private boolean fullscreen; private boolean fullscreen;
private boolean initTrack; private boolean initTrack;
private boolean initAuto; private boolean initAuto;
@ -298,6 +299,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
mR1 = this::hideControl; mR1 = this::hideControl;
mR2 = this::setTraffic; mR2 = this::setTraffic;
mR3 = this::showEmpty; mR3 = this::showEmpty;
setBackground(false);
setRecyclerView(); setRecyclerView();
setVideoView(); setVideoView();
setDanmuView(); setDanmuView();
@ -1118,6 +1120,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onActionEvent(ActionEvent event) { public void onActionEvent(ActionEvent event) {
if (isBackground()) return;
if (ActionEvent.PLAY.equals(event.getAction()) || ActionEvent.PAUSE.equals(event.getAction())) { if (ActionEvent.PLAY.equals(event.getAction()) || ActionEvent.PAUSE.equals(event.getAction())) {
onKeyCenter(); onKeyCenter();
} else if (ActionEvent.NEXT.equals(event.getAction())) { } else if (ActionEvent.NEXT.equals(event.getAction())) {
@ -1131,6 +1134,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onRefreshEvent(RefreshEvent event) {
if (isBackground()) return;
if (event.getType() == RefreshEvent.Type.DETAIL) getDetail(); if (event.getType() == RefreshEvent.Type.DETAIL) getDetail();
else if (event.getType() == RefreshEvent.Type.PLAYER) onRefresh(); else if (event.getType() == RefreshEvent.Type.PLAYER) onRefresh();
else if (event.getType() == RefreshEvent.Type.DANMAKU) checkDanmu(event.getPath()); else if (event.getType() == RefreshEvent.Type.DANMAKU) checkDanmu(event.getPath());
@ -1139,6 +1143,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onPlayerEvent(PlayerEvent event) { public void onPlayerEvent(PlayerEvent event) {
if (isBackground()) return;
switch (event.getState()) { switch (event.getState()) {
case 0: case 0:
setPosition(); setPosition();
@ -1208,6 +1213,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) { public void onErrorEvent(ErrorEvent event) {
if (isBackground()) return;
if (mPlayers.addRetry() > event.getRetry()) checkError(event); if (mPlayers.addRetry() > event.getRetry()) checkError(event);
else onRefresh(); else onRefresh();
} }
@ -1359,6 +1365,14 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
hideCenter(); hideCenter();
} }
public boolean isBackground() {
return background;
}
public void setBackground(boolean background) {
this.background = background;
}
private boolean isFullscreen() { private boolean isFullscreen() {
return fullscreen; return fullscreen;
} }
@ -1545,6 +1559,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
setBackground(false);
mClock.start(); mClock.start();
onPlay(); onPlay();
} }
@ -1552,6 +1567,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
setBackground(true);
onPaused(false); onPaused(false);
mClock.stop(); mClock.stop();
} }

@ -85,9 +85,7 @@ public class ExoUtil {
} }
public static int getRetry(int errorCode) { public static int getRetry(int errorCode) {
if (errorCode == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED || errorCode == PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND) return 0; return errorCode >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && errorCode <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED ? 2 : 1;
if (errorCode == PlaybackException.ERROR_CODE_PARSING_MANIFEST_MALFORMED || errorCode == PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED || errorCode == PlaybackException.ERROR_CODE_IO_UNSPECIFIED) return 2;
return 1;
} }
public static boolean haveTrack(Tracks tracks, int type) { public static boolean haveTrack(Tracks tracks, int type) {
@ -116,6 +114,13 @@ public class ExoUtil {
return MimeTypes.APPLICATION_SUBRIP; return MimeTypes.APPLICATION_SUBRIP;
} }
private static String getMimeType(String format, int errorCode) {
if (format != null) return format;
if (errorCode == PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED || errorCode == PlaybackException.ERROR_CODE_PARSING_MANIFEST_MALFORMED) return MimeTypes.APPLICATION_OCTET;
if (errorCode == PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED || errorCode == PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED) return MimeTypes.APPLICATION_M3U8;
return null;
}
public static MediaSource getSource(Result result, Sub sub, int errorCode) { public static MediaSource getSource(Result result, Sub sub, int errorCode) {
return getSource(result.getHeaders(), result.getRealUrl(), result.getFormat(), result.getSubs(), sub, null, errorCode); return getSource(result.getHeaders(), result.getRealUrl(), result.getFormat(), result.getSubs(), sub, null, errorCode);
} }
@ -146,13 +151,6 @@ public class ExoUtil {
return builder.build(); return builder.build();
} }
private static String getMimeType(String format, int errorCode) {
if (format != null) return format;
if (errorCode == PlaybackException.ERROR_CODE_PARSING_MANIFEST_MALFORMED) return MimeTypes.APPLICATION_OCTET;
if (errorCode == PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED || errorCode == PlaybackException.ERROR_CODE_IO_UNSPECIFIED) return MimeTypes.APPLICATION_M3U8;
return null;
}
private static List<MediaItem.SubtitleConfiguration> getSubtitles(List<Sub> subs) { private static List<MediaItem.SubtitleConfiguration> getSubtitles(List<Sub> subs) {
List<MediaItem.SubtitleConfiguration> items = new ArrayList<>(); List<MediaItem.SubtitleConfiguration> items = new ArrayList<>();
for (Sub sub : subs) items.add(sub.getExo()); for (Sub sub : subs) items.add(sub.getExo());

@ -3,6 +3,7 @@ package com.github.catvod.net.interceptor;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.github.catvod.Proxy;
import com.github.catvod.utils.Util; import com.github.catvod.utils.Util;
import com.google.common.net.HttpHeaders; import com.google.common.net.HttpHeaders;
@ -50,7 +51,8 @@ public class DefaultInterceptor implements Interceptor {
private Request getRequest(@NonNull Request request) { private Request getRequest(@NonNull Request request) {
String url = request.url().toString(); String url = request.url().toString();
Request.Builder builder = request.newBuilder(); Request.Builder builder = request.newBuilder();
if (url.contains("+") && (url.contains("127.0.0.1") || url.contains("/file/"))) builder.url(url.replace("+", "%2B")); boolean local = url.contains(":" + Proxy.getPort() + "/");
if (url.contains("+") && local) builder.url(url.replace("+", "%2B"));
if (url.contains("gitcode.net")) builder.addHeader(HttpHeaders.USER_AGENT, Util.CHROME); if (url.contains("gitcode.net")) builder.addHeader(HttpHeaders.USER_AGENT, Util.CHROME);
return builder.build(); return builder.build();
} }

Loading…
Cancel
Save