|
116 | 116 | import androidx.appcompat.view.ContextThemeWrapper; |
117 | 117 | import androidx.appcompat.widget.AppCompatImageButton; |
118 | 118 | import androidx.appcompat.widget.PopupMenu; |
119 | | -import androidx.collection.ArraySet; |
120 | 119 | import androidx.core.content.ContextCompat; |
121 | 120 | import androidx.core.graphics.Insets; |
122 | 121 | import androidx.core.view.ViewCompat; |
|
135 | 134 | import com.google.android.exoplayer2.Player.PositionInfo; |
136 | 135 | import com.google.android.exoplayer2.RenderersFactory; |
137 | 136 | import com.google.android.exoplayer2.Timeline; |
138 | | -import com.google.android.exoplayer2.TracksInfo; |
| 137 | +import com.google.android.exoplayer2.Tracks; |
139 | 138 | import com.google.android.exoplayer2.source.MediaSource; |
140 | | -import com.google.android.exoplayer2.text.Cue; |
| 139 | +import com.google.android.exoplayer2.text.CueGroup; |
141 | 140 | import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; |
142 | 141 | import com.google.android.exoplayer2.trackselection.MappingTrackSelector; |
143 | 142 | import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; |
@@ -2522,12 +2521,12 @@ public void onEvents(@NonNull final com.google.android.exoplayer2.Player player, |
2522 | 2521 | } |
2523 | 2522 |
|
2524 | 2523 | @Override |
2525 | | - public void onTracksInfoChanged(@NonNull final TracksInfo tracksInfo) { |
| 2524 | + public void onTracksChanged(@NonNull final Tracks tracks) { |
2526 | 2525 | if (DEBUG) { |
2527 | 2526 | Log.d(TAG, "ExoPlayer - onTracksChanged(), " |
2528 | | - + "track group size = " + tracksInfo.getTrackGroupInfos().size()); |
| 2527 | + + "track group size = " + tracks.getGroups().size()); |
2529 | 2528 | } |
2530 | | - onTextTracksChanged(tracksInfo); |
| 2529 | + onTextTracksChanged(tracks); |
2531 | 2530 | } |
2532 | 2531 |
|
2533 | 2532 | @Override |
@@ -2593,8 +2592,8 @@ public void onRenderedFirstFrame() { |
2593 | 2592 | } |
2594 | 2593 |
|
2595 | 2594 | @Override |
2596 | | - public void onCues(@NonNull final List<Cue> cues) { |
2597 | | - binding.subtitleView.onCues(cues); |
| 2595 | + public void onCues(@NonNull final CueGroup cueGroup) { |
| 2596 | + binding.subtitleView.setCues(cueGroup.cues); |
2598 | 2597 | } |
2599 | 2598 | //endregion |
2600 | 2599 |
|
@@ -3679,34 +3678,35 @@ private void setupSubtitleView() { |
3679 | 3678 | binding.subtitleView.setStyle(captionStyle); |
3680 | 3679 | } |
3681 | 3680 |
|
3682 | | - private void onTextTracksChanged(@NonNull final TracksInfo currentTrackInfo) { |
| 3681 | + private void onTextTracksChanged(@NonNull final Tracks currentTrack) { |
3683 | 3682 | if (binding == null) { |
3684 | 3683 | return; |
3685 | 3684 | } |
3686 | 3685 |
|
3687 | | - if (trackSelector.getCurrentMappedTrackInfo() == null |
3688 | | - || !currentTrackInfo.isTypeSupportedOrEmpty(C.TRACK_TYPE_TEXT)) { |
| 3686 | + final boolean trackTypeTextSupported = !currentTrack.containsType(C.TRACK_TYPE_TEXT) |
| 3687 | + || currentTrack.isTypeSupported(C.TRACK_TYPE_TEXT, false); |
| 3688 | + if (trackSelector.getCurrentMappedTrackInfo() == null || !trackTypeTextSupported) { |
3689 | 3689 | binding.captionTextView.setVisibility(View.GONE); |
3690 | 3690 | return; |
3691 | 3691 | } |
3692 | 3692 |
|
3693 | 3693 | // Extract all loaded languages |
3694 | | - final List<TracksInfo.TrackGroupInfo> textTracks = currentTrackInfo |
3695 | | - .getTrackGroupInfos() |
| 3694 | + final List<Tracks.Group> textTracks = currentTrack |
| 3695 | + .getGroups() |
3696 | 3696 | .stream() |
3697 | | - .filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getTrackType()) |
| 3697 | + .filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getType()) |
3698 | 3698 | .collect(Collectors.toList()); |
3699 | 3699 | final List<String> availableLanguages = textTracks.stream() |
3700 | | - .map(TracksInfo.TrackGroupInfo::getTrackGroup) |
| 3700 | + .map(Tracks.Group::getMediaTrackGroup) |
3701 | 3701 | .filter(textTrack -> textTrack.length > 0) |
3702 | 3702 | .map(textTrack -> textTrack.getFormat(0).language) |
3703 | 3703 | .collect(Collectors.toList()); |
3704 | 3704 |
|
3705 | 3705 | // Find selected text track |
3706 | 3706 | final Optional<Format> selectedTracks = textTracks.stream() |
3707 | | - .filter(TracksInfo.TrackGroupInfo::isSelected) |
3708 | | - .filter(info -> info.getTrackGroup().length >= 1) |
3709 | | - .map(info -> info.getTrackGroup().getFormat(0)) |
| 3707 | + .filter(Tracks.Group::isSelected) |
| 3708 | + .filter(info -> info.getMediaTrackGroup().length >= 1) |
| 3709 | + .map(info -> info.getMediaTrackGroup().getFormat(0)) |
3710 | 3710 | .findFirst(); |
3711 | 3711 |
|
3712 | 3712 | // Build UI |
@@ -4256,20 +4256,12 @@ private void useVideoSource(final boolean videoEnabled) { |
4256 | 4256 | return; |
4257 | 4257 | } |
4258 | 4258 |
|
4259 | | - final DefaultTrackSelector.ParametersBuilder parametersBuilder = |
| 4259 | + final DefaultTrackSelector.Parameters.Builder parametersBuilder = |
4260 | 4260 | trackSelector.buildUponParameters(); |
4261 | 4261 |
|
4262 | | - if (videoEnabled) { |
4263 | | - // Enable again the video track and the subtitles, if there is one selected |
4264 | | - parametersBuilder.setDisabledTrackTypes(Collections.emptySet()); |
4265 | | - } else { |
4266 | | - // Disable the video track and the ability to select subtitles |
4267 | | - // Use an ArraySet because we can't use Set.of() on all supported APIs by the app |
4268 | | - final ArraySet<Integer> disabledTracks = new ArraySet<>(); |
4269 | | - disabledTracks.add(C.TRACK_TYPE_TEXT); |
4270 | | - disabledTracks.add(C.TRACK_TYPE_VIDEO); |
4271 | | - parametersBuilder.setDisabledTrackTypes(disabledTracks); |
4272 | | - } |
| 4262 | + // Enable/disable the video track and the ability to select subtitles |
| 4263 | + parametersBuilder.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, !videoEnabled); |
| 4264 | + parametersBuilder.setTrackTypeDisabled(C.TRACK_TYPE_VIDEO, !videoEnabled); |
4273 | 4265 |
|
4274 | 4266 | trackSelector.setParameters(parametersBuilder); |
4275 | 4267 | } |
|
0 commit comments