|
133 | 133 | import com.google.android.exoplayer2.PlaybackParameters; |
134 | 134 | import com.google.android.exoplayer2.Player.PositionInfo; |
135 | 135 | import com.google.android.exoplayer2.RenderersFactory; |
136 | | -import com.google.android.exoplayer2.SeekParameters; |
137 | 136 | import com.google.android.exoplayer2.Timeline; |
138 | 137 | import com.google.android.exoplayer2.TracksInfo; |
139 | 138 | import com.google.android.exoplayer2.source.MediaSource; |
@@ -2487,6 +2486,7 @@ private void setMuteButton(@NonNull final ImageButton button, final boolean isMu |
2487 | 2486 | //////////////////////////////////////////////////////////////////////////*/ |
2488 | 2487 | //region ExoPlayer listeners (that didn't fit in other categories) |
2489 | 2488 |
|
| 2489 | + @Override |
2490 | 2490 | public void onEvents(@NonNull final com.google.android.exoplayer2.Player player, |
2491 | 2491 | @NonNull final com.google.android.exoplayer2.Player.Events events) { |
2492 | 2492 | Listener.super.onEvents(player, events); |
@@ -2546,14 +2546,6 @@ public void onPositionDiscontinuity(@NonNull final PositionInfo oldPosition, |
2546 | 2546 | return; |
2547 | 2547 | } |
2548 | 2548 |
|
2549 | | - if (newPosition.contentPositionMs == 0 && |
2550 | | - simpleExoPlayer.getTotalBufferedDuration() < 500L) { |
2551 | | - Log.d(TAG, "Playback - skipping to initial keyframe."); |
2552 | | - simpleExoPlayer.setSeekParameters(SeekParameters.CLOSEST_SYNC); |
2553 | | - simpleExoPlayer.seekTo(1L); |
2554 | | - simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context)); |
2555 | | - } |
2556 | | - |
2557 | 2549 | // Refresh the playback if there is a transition to the next video |
2558 | 2550 | final int newIndex = newPosition.mediaItemIndex; |
2559 | 2551 | switch (discontinuityReason) { |
@@ -2605,7 +2597,29 @@ public void onCues(@NonNull final List<Cue> cues) { |
2605 | 2597 | //region Errors |
2606 | 2598 | /** |
2607 | 2599 | * Process exceptions produced by {@link com.google.android.exoplayer2.ExoPlayer ExoPlayer}. |
2608 | | - * |
| 2600 | + * <p>There are multiple types of errors:</p> |
| 2601 | + * <ul> |
| 2602 | + * <li>{@link PlaybackException#ERROR_CODE_BEHIND_LIVE_WINDOW BEHIND_LIVE_WINDOW}: |
| 2603 | + * If the playback on livestreams are lagged too far behind the current playable |
| 2604 | + * window. Then we seek to the latest timestamp and restart the playback. |
| 2605 | + * </li> |
| 2606 | + * <li>From {@link PlaybackException#ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE BAD_IO} to |
| 2607 | + * {@link PlaybackException#ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED UNSUPPORTED_FORMATS}: |
| 2608 | + * If the stream source is validated by the extractor but not recognized by the player, |
| 2609 | + * then we can try to recover playback by signal an error on the {@link PlayQueue}.</li> |
| 2610 | + * <li>For {@link PlaybackException#ERROR_CODE_TIMEOUT PLAYER_TIMEOUT}, |
| 2611 | + * {@link PlaybackException#ERROR_CODE_IO_UNSPECIFIED MEDIA_SOURCE_RESOLVER_TIMEOUT} and |
| 2612 | + * {@link PlaybackException#ERROR_CODE_IO_NETWORK_CONNECTION_FAILED NO_NETWORK}: |
| 2613 | + * We can keep set the recovery record and keep to player at the current state until |
| 2614 | + * it is ready to play by restarting the {@link MediaSourceManager}.</li> |
| 2615 | + * <li>On any ExoPlayer specific issue internal to its device interaction, such as |
| 2616 | + * {@link PlaybackException#ERROR_CODE_DECODER_INIT_FAILED DECODER_ERROR}: |
| 2617 | + * We terminate the playback.</li> |
| 2618 | + * <li>For any other unspecified issue internal: We set a recovery and try to restart |
| 2619 | + * the playback.</li> |
| 2620 | + * In the case of decoder/renderer or unspecified errors, the player will create a |
| 2621 | + * notification so the users are aware. |
| 2622 | + * </ul> |
2609 | 2623 | * @see com.google.android.exoplayer2.Player.Listener#onPlayerError(PlaybackException) |
2610 | 2624 | * */ |
2611 | 2625 | @SuppressLint("SwitchIntDef") |
@@ -2648,6 +2662,9 @@ public void onPlayerError(@NonNull final PlaybackException error) { |
2648 | 2662 | case ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT: |
2649 | 2663 | // Don't create notification on timeout/networking errors: |
2650 | 2664 | isCatchableException = true; |
| 2665 | + setRecovery(); |
| 2666 | + reloadPlayQueueManager(); |
| 2667 | + break; |
2651 | 2668 | case ERROR_CODE_UNSPECIFIED: |
2652 | 2669 | // Reload playback on unexpected errors: |
2653 | 2670 | setRecovery(); |
@@ -2749,7 +2766,6 @@ public void onPlaybackSynchronize(@NonNull final PlayQueueItem item, final boole |
2749 | 2766 | return; |
2750 | 2767 | } |
2751 | 2768 |
|
2752 | | - final boolean onPlaybackInitial = currentItem == null; |
2753 | 2769 | final boolean hasPlayQueueItemChanged = currentItem != item; |
2754 | 2770 |
|
2755 | 2771 | final int currentPlayQueueIndex = playQueue.indexOf(item); |
@@ -2953,10 +2969,8 @@ public void fastRewind() { |
2953 | 2969 | //region StreamInfo history: views and progress |
2954 | 2970 |
|
2955 | 2971 | private void registerStreamViewed() { |
2956 | | - getCurrentStreamInfo().ifPresent(info -> { |
2957 | | - databaseUpdateDisposable |
2958 | | - .add(recordManager.onViewed(info).onErrorComplete().subscribe()); |
2959 | | - }); |
| 2972 | + getCurrentStreamInfo().ifPresent(info -> databaseUpdateDisposable |
| 2973 | + .add(recordManager.onViewed(info).onErrorComplete().subscribe())); |
2960 | 2974 | } |
2961 | 2975 |
|
2962 | 2976 | private void saveStreamProgressState(final long progressMillis) { |
@@ -3134,7 +3148,7 @@ public void selectQueueItem(final PlayQueueItem item) { |
3134 | 3148 | return; |
3135 | 3149 | } |
3136 | 3150 |
|
3137 | | - if (playQueue.getIndex() == index && simpleExoPlayer.getCurrentWindowIndex() == index) { |
| 3151 | + if (playQueue.getIndex() == index && simpleExoPlayer.getCurrentMediaItemIndex() == index) { |
3138 | 3152 | seekToDefault(); |
3139 | 3153 | } else { |
3140 | 3154 | saveStreamProgressState(); |
@@ -3880,9 +3894,10 @@ private void onPlayWithKodiClicked() { |
3880 | 3894 | } |
3881 | 3895 |
|
3882 | 3896 | private void onOpenInBrowserClicked() { |
3883 | | - getCurrentStreamInfo().map(Info::getOriginalUrl).ifPresent(originalUrl -> { |
3884 | | - ShareUtils.openUrlInBrowser(Objects.requireNonNull(getParentActivity()), originalUrl); |
3885 | | - }); |
| 3897 | + getCurrentStreamInfo() |
| 3898 | + .map(Info::getOriginalUrl) |
| 3899 | + .ifPresent(originalUrl -> ShareUtils.openUrlInBrowser( |
| 3900 | + Objects.requireNonNull(getParentActivity()), originalUrl)); |
3886 | 3901 | } |
3887 | 3902 | //endregion |
3888 | 3903 |
|
|
0 commit comments