diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java index 34c417b5e..c029ad795 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.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(); diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java index d034e8a56..a1a26a886 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java @@ -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(); diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java index 4648541cf..49dc708a7 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java @@ -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()); diff --git a/app/src/main/java/com/fongmi/android/tv/event/ErrorEvent.java b/app/src/main/java/com/fongmi/android/tv/event/ErrorEvent.java index 4029c7ee5..d2b9bfe0e 100644 --- a/app/src/main/java/com/fongmi/android/tv/event/ErrorEvent.java +++ b/app/src/main/java/com/fongmi/android/tv/event/ErrorEvent.java @@ -49,6 +49,10 @@ public class ErrorEvent { return type; } + public int getCode() { + return code; + } + public boolean isDecode() { return code / 1000 == 4; } diff --git a/app/src/main/java/com/fongmi/android/tv/player/Players.java b/app/src/main/java/com/fongmi/android/tv/player/Players.java index 6ead765d0..fc09c23c1 100644 --- a/app/src/main/java/com/fongmi/android/tv/player/Players.java +++ b/app/src/main/java/com/fongmi/android/tv/player/Players.java @@ -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) { diff --git a/app/src/main/java/com/fongmi/android/tv/player/exo/ExoUtil.java b/app/src/main/java/com/fongmi/android/tv/player/exo/ExoUtil.java index 1077238b9..1dde12787 100644 --- a/app/src/main/java/com/fongmi/android/tv/player/exo/ExoUtil.java +++ b/app/src/main/java/com/fongmi/android/tv/player/exo/ExoUtil.java @@ -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; } diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java index 876857d80..1aceed453 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java @@ -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(); diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java index 4dd4e0da5..a2a659524 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java @@ -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());