|
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; |
@@ -2506,12 +2505,12 @@ public void onEvents(@NonNull final com.google.android.exoplayer2.Player player, |
2506 | 2505 | } |
2507 | 2506 |
|
2508 | 2507 | @Override |
2509 | | - public void onTracksInfoChanged(@NonNull final TracksInfo tracksInfo) { |
| 2508 | + public void onTracksChanged(@NonNull final Tracks tracks) { |
2510 | 2509 | if (DEBUG) { |
2511 | 2510 | Log.d(TAG, "ExoPlayer - onTracksChanged(), " |
2512 | | - + "track group size = " + tracksInfo.getTrackGroupInfos().size()); |
| 2511 | + + "track group size = " + tracks.getGroups().size()); |
2513 | 2512 | } |
2514 | | - onTextTracksChanged(tracksInfo); |
| 2513 | + onTextTracksChanged(tracks); |
2515 | 2514 | } |
2516 | 2515 |
|
2517 | 2516 | @Override |
@@ -2577,8 +2576,8 @@ public void onRenderedFirstFrame() { |
2577 | 2576 | } |
2578 | 2577 |
|
2579 | 2578 | @Override |
2580 | | - public void onCues(@NonNull final List<Cue> cues) { |
2581 | | - binding.subtitleView.onCues(cues); |
| 2579 | + public void onCues(@NonNull final CueGroup cueGroup) { |
| 2580 | + binding.subtitleView.setCues(cueGroup.cues); |
2582 | 2581 | } |
2583 | 2582 | //endregion |
2584 | 2583 |
|
@@ -3665,34 +3664,35 @@ private void setupSubtitleView() { |
3665 | 3664 | binding.subtitleView.setStyle(captionStyle); |
3666 | 3665 | } |
3667 | 3666 |
|
3668 | | - private void onTextTracksChanged(@NonNull final TracksInfo currentTrackInfo) { |
| 3667 | + private void onTextTracksChanged(@NonNull final Tracks currentTrack) { |
3669 | 3668 | if (binding == null) { |
3670 | 3669 | return; |
3671 | 3670 | } |
3672 | 3671 |
|
3673 | | - if (trackSelector.getCurrentMappedTrackInfo() == null |
3674 | | - || !currentTrackInfo.isTypeSupportedOrEmpty(C.TRACK_TYPE_TEXT)) { |
| 3672 | + final boolean trackTypeTextSupported = !currentTrack.containsType(C.TRACK_TYPE_TEXT) |
| 3673 | + || currentTrack.isTypeSupported(C.TRACK_TYPE_TEXT, false); |
| 3674 | + if (trackSelector.getCurrentMappedTrackInfo() == null || !trackTypeTextSupported) { |
3675 | 3675 | binding.captionTextView.setVisibility(View.GONE); |
3676 | 3676 | return; |
3677 | 3677 | } |
3678 | 3678 |
|
3679 | 3679 | // Extract all loaded languages |
3680 | | - final List<TracksInfo.TrackGroupInfo> textTracks = currentTrackInfo |
3681 | | - .getTrackGroupInfos() |
| 3680 | + final List<Tracks.Group> textTracks = currentTrack |
| 3681 | + .getGroups() |
3682 | 3682 | .stream() |
3683 | | - .filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getTrackType()) |
| 3683 | + .filter(trackGroupInfo -> C.TRACK_TYPE_TEXT == trackGroupInfo.getType()) |
3684 | 3684 | .collect(Collectors.toList()); |
3685 | 3685 | final List<String> availableLanguages = textTracks.stream() |
3686 | | - .map(TracksInfo.TrackGroupInfo::getTrackGroup) |
| 3686 | + .map(Tracks.Group::getMediaTrackGroup) |
3687 | 3687 | .filter(textTrack -> textTrack.length > 0) |
3688 | 3688 | .map(textTrack -> textTrack.getFormat(0).language) |
3689 | 3689 | .collect(Collectors.toList()); |
3690 | 3690 |
|
3691 | 3691 | // Find selected text track |
3692 | 3692 | final Optional<Format> selectedTracks = textTracks.stream() |
3693 | | - .filter(TracksInfo.TrackGroupInfo::isSelected) |
3694 | | - .filter(info -> info.getTrackGroup().length >= 1) |
3695 | | - .map(info -> info.getTrackGroup().getFormat(0)) |
| 3693 | + .filter(Tracks.Group::isSelected) |
| 3694 | + .filter(info -> info.getMediaTrackGroup().length >= 1) |
| 3695 | + .map(info -> info.getMediaTrackGroup().getFormat(0)) |
3696 | 3696 | .findFirst(); |
3697 | 3697 |
|
3698 | 3698 | // Build UI |
@@ -4240,20 +4240,12 @@ private void useVideoSource(final boolean videoEnabled) { |
4240 | 4240 | return; |
4241 | 4241 | } |
4242 | 4242 |
|
4243 | | - final DefaultTrackSelector.ParametersBuilder parametersBuilder = |
| 4243 | + final DefaultTrackSelector.Parameters.Builder parametersBuilder = |
4244 | 4244 | trackSelector.buildUponParameters(); |
4245 | 4245 |
|
4246 | | - if (videoEnabled) { |
4247 | | - // Enable again the video track and the subtitles, if there is one selected |
4248 | | - parametersBuilder.setDisabledTrackTypes(Collections.emptySet()); |
4249 | | - } else { |
4250 | | - // Disable the video track and the ability to select subtitles |
4251 | | - // Use an ArraySet because we can't use Set.of() on all supported APIs by the app |
4252 | | - final ArraySet<Integer> disabledTracks = new ArraySet<>(); |
4253 | | - disabledTracks.add(C.TRACK_TYPE_TEXT); |
4254 | | - disabledTracks.add(C.TRACK_TYPE_VIDEO); |
4255 | | - parametersBuilder.setDisabledTrackTypes(disabledTracks); |
4256 | | - } |
| 4246 | + // Enable/disable the video track and the ability to select subtitles |
| 4247 | + parametersBuilder.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, !videoEnabled); |
| 4248 | + parametersBuilder.setTrackTypeDisabled(C.TRACK_TYPE_VIDEO, !videoEnabled); |
4257 | 4249 |
|
4258 | 4250 | trackSelector.setParameters(parametersBuilder); |
4259 | 4251 | } |
|
0 commit comments