From 8f7d5b30c00a4df4e0be4ef9ae53a79ec25db00b Mon Sep 17 00:00:00 2001 From: okjack Date: Fri, 13 Sep 2024 17:55:32 +0800 Subject: [PATCH] Fix exo bug --- .../com/fongmi/android/tv/ui/activity/CastActivity.java | 7 ++++--- .../com/fongmi/android/tv/ui/activity/LiveActivity.java | 7 ++++--- .../com/fongmi/android/tv/ui/activity/VideoActivity.java | 7 ++++--- .../main/java/com/fongmi/android/tv/event/ErrorEvent.java | 4 ++-- .../com/fongmi/android/tv/ui/activity/LiveActivity.java | 7 ++++--- .../com/fongmi/android/tv/ui/activity/VideoActivity.java | 7 ++++--- 6 files changed, 22 insertions(+), 17 deletions(-) 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 507d81efb..fe96e3c38 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 @@ -14,6 +14,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.media3.ui.PlayerView; import androidx.viewbinding.ViewBinding; @@ -372,12 +373,12 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List public void onErrorEvent(ErrorEvent event) { if (mPlayers.addRetry() > event.getRetry()) onError(event); else if (event.isDecode() && mPlayers.canToggleDecode()) onDecode(false); - else if (event.isFormat() && mPlayers.isExo()) onErrorFormat(event); + else if (event.isExo() && mPlayers.isExo()) onExoCheck(event); else onReset(); } - private void onErrorFormat(ErrorEvent event) { - mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); + private void onExoCheck(ErrorEvent event) { + if (event.getCode() == PlaybackException.ERROR_CODE_IO_UNSPECIFIED || event.getCode() >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && event.getCode() <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED) mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); mPlayers.setMediaSource(); } 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 51fdb561c..602333af2 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.media3.ui.PlayerView; import androidx.recyclerview.widget.RecyclerView; @@ -818,12 +819,12 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, GroupP if (addErrorCount() > 20) onErrorEnd(event); else if (mPlayers.addRetry() > event.getRetry()) checkError(event); else if (event.isDecode() && mPlayers.canToggleDecode()) onDecode(false); - else if (event.isFormat() && mPlayers.isExo()) onErrorFormat(event); + else if (event.isExo() && mPlayers.isExo()) onExoCheck(event); else fetch(); } - private void onErrorFormat(ErrorEvent event) { - mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); + private void onExoCheck(ErrorEvent event) { + if (event.getCode() == PlaybackException.ERROR_CODE_IO_UNSPECIFIED || event.getCode() >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && event.getCode() <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED) mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); mPlayers.setMediaSource(); } 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 dd654fe7b..348aa83d7 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 @@ -28,6 +28,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.media3.ui.PlayerView; import androidx.recyclerview.widget.RecyclerView; @@ -1434,12 +1435,12 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List if (addErrorCount() > 20) onErrorEnd(event); else if (mPlayers.addRetry() > event.getRetry()) checkError(event); else if (event.isDecode() && mPlayers.canToggleDecode()) onDecode(false); - else if (event.isFormat() && mPlayers.isExo()) onErrorFormat(event); + else if (event.isExo() && mPlayers.isExo()) onExoCheck(event); else onRefresh(); } - private void onErrorFormat(ErrorEvent event) { - mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); + private void onExoCheck(ErrorEvent event) { + if (event.getCode() == PlaybackException.ERROR_CODE_IO_UNSPECIFIED || event.getCode() >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && event.getCode() <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED) mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); mPlayers.setMediaSource(); } 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 16056bbbb..295421c0d 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 @@ -69,8 +69,8 @@ public class ErrorEvent { return code / 1000 == 4; } - public boolean isFormat() { - return code / 1000 == 3; + public boolean isExo() { + return code / 1000 == 2 || code / 1000 == 3 || code / 1000 == 4; } public String getMsg() { 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 efcb78d70..abd644d6e 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.media3.ui.PlayerView; import androidx.viewbinding.ViewBinding; @@ -884,12 +885,12 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, Custom if (addErrorCount() > 20) onErrorEnd(event); else if (mPlayers.addRetry() > event.getRetry()) checkError(event); else if (event.isDecode() && mPlayers.canToggleDecode()) onDecode(false); - else if (event.isFormat() && mPlayers.isExo()) onErrorFormat(event); + else if (event.isExo() && mPlayers.isExo()) onExoCheck(event); else fetch(); } - private void onErrorFormat(ErrorEvent event) { - mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); + private void onExoCheck(ErrorEvent event) { + if (event.getCode() == PlaybackException.ERROR_CODE_IO_UNSPECIFIED || event.getCode() >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && event.getCode() <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED) mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); mPlayers.setMediaSource(); } 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 50a8f46db..c796f4e5f 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.media3.ui.PlayerView; import androidx.recyclerview.widget.RecyclerView; @@ -1385,12 +1386,12 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo if (addErrorCount() > 20) onErrorEnd(event); else if (mPlayers.addRetry() > event.getRetry()) checkError(event); else if (event.isDecode() && mPlayers.canToggleDecode()) onDecode(false); - else if (event.isFormat() && mPlayers.isExo()) onErrorFormat(event); + else if (event.isExo() && mPlayers.isExo()) onExoCheck(event); else onRefresh(); } - private void onErrorFormat(ErrorEvent event) { - mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); + private void onExoCheck(ErrorEvent event) { + if (event.getCode() == PlaybackException.ERROR_CODE_IO_UNSPECIFIED || event.getCode() >= PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED && event.getCode() <= PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED) mPlayers.setFormat(ExoUtil.getMimeType(event.getCode())); mPlayers.setMediaSource(); }