|
68 | 68 | import androidx.appcompat.view.ContextThemeWrapper; |
69 | 69 | import androidx.appcompat.widget.AppCompatImageButton; |
70 | 70 | import androidx.appcompat.widget.PopupMenu; |
71 | | -import androidx.collection.ArraySet; |
72 | 71 | import androidx.core.content.ContextCompat; |
73 | 72 | import androidx.core.graphics.Insets; |
74 | 73 | import androidx.core.view.GestureDetectorCompat; |
|
81 | 80 |
|
82 | 81 | import com.google.android.exoplayer2.*; |
83 | 82 | import com.google.android.exoplayer2.Player.PositionInfo; |
| 83 | +import com.google.android.exoplayer2.RenderersFactory; |
| 84 | +import com.google.android.exoplayer2.Timeline; |
| 85 | +import com.google.android.exoplayer2.Tracks; |
84 | 86 | import com.google.android.exoplayer2.source.MediaSource; |
85 | | -import com.google.android.exoplayer2.text.Cue; |
| 87 | +import com.google.android.exoplayer2.text.CueGroup; |
86 | 88 | import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; |
87 | 89 | import com.google.android.exoplayer2.trackselection.MappingTrackSelector; |
88 | 90 | import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; |
@@ -2916,15 +2918,15 @@ public void onEvents(@NonNull final com.google.android.exoplayer2.Player player, |
2916 | 2918 | } |
2917 | 2919 |
|
2918 | 2920 | @Override |
2919 | | - public void onTracksInfoChanged(@NonNull final TracksInfo tracksInfo) { |
| 2921 | + public void onTracksChanged(@NonNull final Tracks tracks) { |
2920 | 2922 | if (DEBUG) { |
2921 | 2923 | Log.d(TAG, "ExoPlayer - onTracksChanged(), " |
2922 | | - + "track group size = " + tracksInfo.getTrackGroupInfos().size()); |
| 2924 | + + "track group size = " + tracks.getGroups().size()); |
2923 | 2925 | } |
2924 | 2926 | if(enqueueTimer != null){ |
2925 | 2927 | enqueueTimer.cancel(true); |
2926 | 2928 | } |
2927 | | - onTextTracksChanged(tracksInfo); |
| 2929 | + onTextTracksChanged(tracks); |
2928 | 2930 | } |
2929 | 2931 |
|
2930 | 2932 | @Override |
@@ -2990,8 +2992,8 @@ public void onRenderedFirstFrame() { |
2990 | 2992 | } |
2991 | 2993 |
|
2992 | 2994 | @Override |
2993 | | - public void onCues(@NonNull final List<Cue> cues) { |
2994 | | - binding.subtitleView.onCues(cues); |
| 2995 | + public void onCues(@NonNull final CueGroup cueGroup) { |
| 2996 | + binding.subtitleView.setCues(cueGroup.cues); |
2995 | 2997 | } |
2996 | 2998 | //endregion |
2997 | 2999 |
|
@@ -4137,35 +4139,36 @@ private void setupSubtitleView() { |
4137 | 4139 | binding.subtitleView.setStyle(captionStyle); |
4138 | 4140 | } |
4139 | 4141 |
|
4140 | | - private void onTextTracksChanged(@NonNull final TracksInfo currentTrackInfo) { |
| 4142 | + private void onTextTracksChanged(@NonNull final Tracks currentTrack) { |
4141 | 4143 | if (binding == null) { |
4142 | 4144 | return; |
4143 | 4145 | } |
4144 | 4146 |
|
4145 | | - if (trackSelector.getCurrentMappedTrackInfo() == null |
4146 | | - || !currentTrackInfo.isTypeSupportedOrEmpty(C.TRACK_TYPE_TEXT)) { |
| 4147 | + final boolean trackTypeTextSupported = !currentTrack.containsType(C.TRACK_TYPE_TEXT) |
| 4148 | + || currentTrack.isTypeSupported(C.TRACK_TYPE_TEXT, false); |
| 4149 | + if (trackSelector.getCurrentMappedTrackInfo() == null || !trackTypeTextSupported) { |
4147 | 4150 | binding.captionTextView.setVisibility(View.GONE); |
4148 | 4151 | return; |
4149 | 4152 | } |
4150 | 4153 |
|
4151 | 4154 | // Extract all loaded languages |
4152 | | - final List<TracksInfo.TrackGroupInfo> textTracks = currentTrackInfo |
4153 | | - .getTrackGroupInfos() |
| 4155 | + final List<Tracks.Group> textTracks = currentTrack |
| 4156 | + .getGroups() |
4154 | 4157 | .stream() |
4155 | | - .filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getTrackType()) |
| 4158 | + .filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getType()) |
4156 | 4159 | .collect(Collectors.toList()); |
4157 | 4160 | final List<String> availableLanguages = textTracks.stream() |
4158 | | - .map(TracksInfo.TrackGroupInfo::getTrackGroup) |
| 4161 | + .map(Tracks.Group::getMediaTrackGroup) |
4159 | 4162 | .filter(textTrack -> textTrack.length > 0) |
4160 | 4163 | .map(textTrack -> textTrack.getFormat(0).language) |
4161 | 4164 | .filter(Objects::nonNull) |
4162 | 4165 | .collect(Collectors.toList()); |
4163 | 4166 |
|
4164 | 4167 | // Find selected text track |
4165 | 4168 | final Optional<Format> selectedTracks = textTracks.stream() |
4166 | | - .filter(TracksInfo.TrackGroupInfo::isSelected) |
4167 | | - .filter(info -> info.getTrackGroup().length >= 1) |
4168 | | - .map(info -> info.getTrackGroup().getFormat(0)) |
| 4169 | + .filter(Tracks.Group::isSelected) |
| 4170 | + .filter(info -> info.getMediaTrackGroup().length >= 1) |
| 4171 | + .map(info -> info.getMediaTrackGroup().getFormat(0)) |
4169 | 4172 | .findFirst(); |
4170 | 4173 |
|
4171 | 4174 | // Build UI |
@@ -4745,20 +4748,12 @@ private void useVideoSource(final boolean videoEnabled) { |
4745 | 4748 | return; |
4746 | 4749 | } |
4747 | 4750 |
|
4748 | | - final DefaultTrackSelector.ParametersBuilder parametersBuilder = |
| 4751 | + final DefaultTrackSelector.Parameters.Builder parametersBuilder = |
4749 | 4752 | trackSelector.buildUponParameters(); |
4750 | 4753 |
|
4751 | | - if (videoEnabled) { |
4752 | | - // Enable again the video track and the subtitles, if there is one selected |
4753 | | - parametersBuilder.setDisabledTrackTypes(Collections.emptySet()); |
4754 | | - } else { |
4755 | | - // Disable the video track and the ability to select subtitles |
4756 | | - // Use an ArraySet because we can't use Set.of() on all supported APIs by the app |
4757 | | - final ArraySet<Integer> disabledTracks = new ArraySet<>(); |
4758 | | - disabledTracks.add(C.TRACK_TYPE_TEXT); |
4759 | | - disabledTracks.add(C.TRACK_TYPE_VIDEO); |
4760 | | - parametersBuilder.setDisabledTrackTypes(disabledTracks); |
4761 | | - } |
| 4754 | + // Enable/disable the video track and the ability to select subtitles |
| 4755 | + parametersBuilder.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, !videoEnabled); |
| 4756 | + parametersBuilder.setTrackTypeDisabled(C.TRACK_TYPE_VIDEO, !videoEnabled); |
4762 | 4757 |
|
4763 | 4758 | trackSelector.setParameters(parametersBuilder); |
4764 | 4759 | } |
@@ -5265,7 +5260,7 @@ public void setLongPressSpeedingEnabled(boolean enabled) { |
5265 | 5260 | public boolean getLongPressSpeedingEnabled() { |
5266 | 5261 | return longPressSpeedingEnabled; |
5267 | 5262 | } |
5268 | | - |
| 5263 | + |
5269 | 5264 | public void onBufferingFailed() { |
5270 | 5265 | pause(); |
5271 | 5266 | pauseBCPlayer(); |
|
0 commit comments