Optimize exo error check

release
FongMi 2 years ago
parent 5111a03f4e
commit f5e8e2fef1
  1. 12
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java
  2. 12
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  3. 12
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  4. 4
      app/src/main/java/com/fongmi/android/tv/event/ErrorEvent.java
  5. 8
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  6. 3
      app/src/main/java/com/fongmi/android/tv/player/exo/ExoUtil.java
  7. 12
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  8. 12
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java

@ -13,6 +13,7 @@ import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.viewbinding.ViewBinding;
@ -133,7 +134,7 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
}
private void setVideoView() {
mPlayers.setup(mBinding.exo);
mPlayers.init(mBinding.exo);
setScale(scale = Setting.getScale());
findViewById(R.id.timeBar).setNextFocusUpId(R.id.reset);
mBinding.control.speed.setText(mPlayers.getSpeedText());
@ -339,10 +340,17 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (mPlayers.retried()) onError(event);
else if (event.isDecode()) onDecode();
else if (event.isDecode()) onCheck(event);
else onReset();
}
private void onCheck(ErrorEvent event) {
if (event.getCode() == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED) mPlayers.init(mBinding.exo);
else mPlayers.toggleDecode(mBinding.exo);
setDecode();
onReset();
}
private void onError(ErrorEvent event) {
showError(event.getMsg());
onStopped();

@ -15,6 +15,7 @@ import androidx.leanback.widget.ItemBridgeAdapter;
import androidx.leanback.widget.OnChildViewHolderSelectedListener;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
@ -177,7 +178,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
}
private void setVideoView() {
mPlayers.setup(mBinding.exo);
mPlayers.init(mBinding.exo);
setScale(Setting.getLiveScale());
findViewById(R.id.timeBar).setNextFocusUpId(R.id.player);
mBinding.control.invert.setActivated(Setting.isInvert());
@ -727,10 +728,17 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (mPlayers.retried()) onError(event);
else if (event.isDecode()) onDecode();
else if (event.isDecode()) onCheck(event);
else fetch();
}
private void onCheck(ErrorEvent event) {
if (event.getCode() == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED) mPlayers.init(mBinding.exo);
else mPlayers.toggleDecode(mBinding.exo);
setDecode();
fetch();
}
private void onError(ErrorEvent event) {
showError(event.getMsg());
mPlayers.reset();

@ -27,6 +27,7 @@ import androidx.leanback.widget.ItemBridgeAdapter;
import androidx.leanback.widget.OnChildViewHolderSelectedListener;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
@ -373,7 +374,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
}
private void setVideoView() {
mPlayers.setup(mBinding.exo);
mPlayers.init(mBinding.exo);
mBinding.control.decode.setText(mPlayers.getDecodeText());
mBinding.control.speed.setEnabled(mPlayers.canAdjustSpeed());
mBinding.control.reset.setText(ResUtil.getStringArray(R.array.select_reset)[Setting.getReset()]);
@ -1135,10 +1136,17 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
public void onErrorEvent(ErrorEvent event) {
if (isBackground()) return;
if (mPlayers.retried()) onError(event);
else if (event.isDecode()) onDecode();
else if (event.isDecode()) onCheck(event);
else onRefresh();
}
private void onCheck(ErrorEvent event) {
if (event.getCode() == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED) mPlayers.init(mBinding.exo);
else mPlayers.toggleDecode(mBinding.exo);
setDecode();
onRefresh();
}
private void onError(ErrorEvent event) {
Track.delete(getHistoryKey());
showError(event.getMsg());

@ -49,6 +49,10 @@ public class ErrorEvent {
return type;
}
public int getCode() {
return code;
}
public boolean isDecode() {
return code / 1000 == 4;
}

@ -106,12 +106,12 @@ public class Players implements Player.Listener, ParseCallback {
MediaControllerCompat.setMediaController(activity, session.getController());
}
public void setup(PlayerView exo) {
public void init(PlayerView exo) {
releasePlayer();
setupExo(exo);
initExo(exo);
}
private void setupExo(PlayerView exo) {
private void initExo(PlayerView exo) {
exoPlayer = new ExoPlayer.Builder(App.get()).setLoadControl(ExoUtil.buildLoadControl()).setTrackSelector(ExoUtil.buildTrackSelector()).setRenderersFactory(ExoUtil.buildRenderersFactory(decode)).setMediaSourceFactory(ExoUtil.buildMediaSourceFactory()).build();
exoPlayer.setAudioAttributes(AudioAttributes.DEFAULT, true);
exoPlayer.addAnalyticsListener(new EventLogger());
@ -273,7 +273,7 @@ public class Players implements Player.Listener, ParseCallback {
public void toggleDecode(PlayerView exo) {
Setting.putDecode(decode = isHard() ? SOFT : HARD);
setup(exo);
init(exo);
}
public String getPositionTime(long time) {

@ -98,7 +98,8 @@ public class ExoUtil {
public static int getRetry(int errorCode) {
if (errorCode == PlaybackException.ERROR_CODE_IO_UNSPECIFIED) return 2;
if (errorCode >= PlaybackException.ERROR_CODE_DECODER_INIT_FAILED && errorCode <= PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) return 2;
if (errorCode == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED) return 1;
if (errorCode >= PlaybackException.ERROR_CODE_DECODER_QUERY_FAILED && errorCode <= PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) return 2;
if (errorCode >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && errorCode <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED) return 2;
return 1;
}

@ -17,6 +17,7 @@ import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.viewbinding.ViewBinding;
@ -200,7 +201,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
}
private void setVideoView() {
mPlayers.setup(mBinding.exo);
mPlayers.init(mBinding.exo);
setScale(Setting.getLiveScale());
mBinding.control.action.invert.setActivated(Setting.isInvert());
mBinding.control.action.across.setActivated(Setting.isAcross());
@ -786,10 +787,17 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
@Subscribe(threadMode = ThreadMode.MAIN)
public void onErrorEvent(ErrorEvent event) {
if (mPlayers.retried()) onError(event);
else if (event.isDecode()) onDecode();
else if (event.isDecode()) onCheck(event);
else fetch();
}
private void onCheck(ErrorEvent event) {
if (event.getCode() == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED) mPlayers.init(mBinding.exo);
else mPlayers.toggleDecode(mBinding.exo);
setDecode();
fetch();
}
private void onError(ErrorEvent event) {
showError(event.getMsg());
mPlayers.reset();

@ -32,6 +32,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
@ -367,7 +368,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
}
private void setVideoView() {
mPlayers.setup(mBinding.exo);
mPlayers.init(mBinding.exo);
if (isPort() && ResUtil.isLand(this)) enterFullscreen();
mBinding.control.action.decode.setText(mPlayers.getDecodeText());
mBinding.control.action.speed.setEnabled(mPlayers.canAdjustSpeed());
@ -1154,10 +1155,17 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
public void onErrorEvent(ErrorEvent event) {
if (isRedirect()) return;
if (mPlayers.retried()) onError(event);
else if (event.isDecode()) onDecode();
else if (event.isDecode()) onCheck(event);
else onRefresh();
}
private void onCheck(ErrorEvent event) {
if (event.getCode() == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED) mPlayers.init(mBinding.exo);
else mPlayers.toggleDecode(mBinding.exo);
setDecode();
onRefresh();
}
private void onError(ErrorEvent event) {
mBinding.swipeLayout.setEnabled(true);
Track.delete(getHistoryKey());

Loading…
Cancel
Save