Auto change decode

pull/497/head
FongMi 2 years ago
parent 0717f89ad2
commit a4d67cf1cb
  1. 3
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java
  2. 3
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  3. 3
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  4. 33
      app/src/main/java/com/fongmi/android/tv/event/ErrorEvent.java
  5. 4
      app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java
  6. 6
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  7. 3
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  8. 3
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java

@ -342,7 +342,8 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (mPlayers.addRetry() > event.getRetry()) onError(event);
if (event.getCode() / 1000 == 4 && Players.isHard()) onDecode();
else if (mPlayers.addRetry() > 1) onError(event);
else onReset();
}

@ -718,7 +718,8 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (mPlayers.addRetry() > event.getRetry()) onError(event);
if (event.getCode() / 1000 == 4 && Players.isHard()) onDecode();
else if (mPlayers.addRetry() > 1) onError(event);
else fetch();
}

@ -1138,7 +1138,8 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (isBackground()) return;
if (mPlayers.addRetry() > event.getRetry()) onError(event);
if (event.getCode() / 1000 == 4 && Players.isHard()) onDecode();
else if (mPlayers.addRetry() > 1) onError(event);
else onRefresh();
}

@ -8,50 +8,49 @@ import org.greenrobot.eventbus.EventBus;
public class ErrorEvent {
private final Type type;
private final int retry;
private String msg;
private int code;
public static void url(int retry) {
EventBus.getDefault().post(new ErrorEvent(Type.URL, retry));
public static void url() {
EventBus.getDefault().post(new ErrorEvent(Type.URL, -1));
}
public static void url(int code) {
EventBus.getDefault().post(new ErrorEvent(Type.URL, code));
}
public static void flag() {
EventBus.getDefault().post(new ErrorEvent(Type.FLAG, 0));
EventBus.getDefault().post(new ErrorEvent(Type.FLAG, -1));
}
public static void parse() {
EventBus.getDefault().post(new ErrorEvent(Type.PARSE, 0));
EventBus.getDefault().post(new ErrorEvent(Type.PARSE, -1));
}
public static void timeout() {
EventBus.getDefault().post(new ErrorEvent(Type.TIMEOUT, 0));
EventBus.getDefault().post(new ErrorEvent(Type.TIMEOUT, -1));
}
public static void extract(String msg) {
EventBus.getDefault().post(new ErrorEvent(Type.EXTRACT, 0, msg));
EventBus.getDefault().post(new ErrorEvent(Type.EXTRACT, msg));
}
public ErrorEvent(Type type, int retry) {
public ErrorEvent(Type type, int code) {
this.type = type;
this.retry = retry;
this.code = code;
}
public ErrorEvent(Type type, int retry, String msg) {
public ErrorEvent(Type type, String msg) {
this.msg = msg;
this.type = type;
this.retry = retry;
}
public Type getType() {
return type;
}
public int getRetry() {
return retry;
}
public boolean isUrl() {
return Type.URL.equals(getType());
public int getCode() {
return code;
}
public String getMsg() {

@ -83,10 +83,6 @@ public class ExoUtil {
return Setting.isCaption() ? CaptionStyleCompat.createFromCaptionStyle(((CaptioningManager) App.get().getSystemService(Context.CAPTIONING_SERVICE)).getUserStyle()) : new CaptionStyleCompat(Color.WHITE, Color.TRANSPARENT, Color.TRANSPARENT, CaptionStyleCompat.EDGE_TYPE_OUTLINE, Color.BLACK, null);
}
public static int getRetry(int errorCode) {
return errorCode >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && errorCode <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED ? 2 : 1;
}
public static boolean haveTrack(Tracks tracks, int type) {
int count = 0;
for (Tracks.Group trackGroup : tracks.getGroups()) if (trackGroup.getType() == type) count += trackGroup.length;

@ -328,7 +328,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
} else if (channel.getParse() == 1) {
startParse(channel.result(), false);
} else if (isIllegal(channel.getUrl())) {
ErrorEvent.url(0);
ErrorEvent.url();
} else {
setMediaSource(channel, timeout);
}
@ -340,7 +340,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
} else if (result.getParse(1) == 1 || result.getJx() == 1) {
startParse(result, useParse);
} else if (isIllegal(result.getRealUrl())) {
ErrorEvent.url(0);
ErrorEvent.url();
} else {
setMediaSource(result, timeout);
}
@ -502,8 +502,8 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
@Override
public void onPlayerError(@NonNull PlaybackException error) {
ErrorEvent.url(ExoUtil.getRetry(this.error = error.errorCode));
setPlaybackState(PlaybackStateCompat.STATE_ERROR);
ErrorEvent.url(error.errorCode);
}
@Override

@ -778,7 +778,8 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (mPlayers.addRetry() > event.getRetry()) onError(event);
if (event.getCode() / 1000 == 4 && Players.isHard()) onDecode();
else if (mPlayers.addRetry() > 1) onError(event);
else fetch();
}

@ -1149,7 +1149,8 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (isRedirect()) return;
if (mPlayers.addRetry() > event.getRetry()) onError(event);
if (event.getCode() / 1000 == 4 && Players.isHard()) onDecode();
else if (mPlayers.addRetry() > 1) onError(event);
else onRefresh();
}

Loading…
Cancel
Save