Java Code Examples for com.google.android.exoplayer2.trackselection.MappingTrackSelector#MappedTrackInfo
The following examples show how to use
com.google.android.exoplayer2.trackselection.MappingTrackSelector#MappedTrackInfo .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 6 votes |
public int getSelectedTrackIndex(@NonNull RendererType type, int groupIndex) { // Retrieves the available tracks MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, groupIndex, mappedTrackInfo); TrackGroupArray trackGroupArray = tracksInfo.rendererTrackIndex == C.INDEX_UNSET ? null : mappedTrackInfo.getTrackGroups(tracksInfo.rendererTrackIndex); if (trackGroupArray == null || trackGroupArray.length == 0) { return -1; } // Verifies the track selection has been overridden DefaultTrackSelector.SelectionOverride selectionOverride = trackSelector.getParameters().getSelectionOverride(tracksInfo.rendererTrackIndex, trackGroupArray); if (selectionOverride == null || selectionOverride.groupIndex != tracksInfo.rendererTrackGroupIndex || selectionOverride.length <= 0) { return -1; } return selectionOverride.tracks[0]; // In the current implementation only one track can be selected at a time so get the first one. }
Example 2
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 6 votes |
public void setRendererEnabled(@NonNull RendererType type, boolean enabled) { MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo); if (!tracksInfo.rendererTrackIndexes.isEmpty()) { boolean enabledSomething = false; DefaultTrackSelector.ParametersBuilder parametersBuilder = trackSelector.buildUponParameters(); for (int rendererTrackIndex : tracksInfo.rendererTrackIndexes) { if (enabled) { DefaultTrackSelector.SelectionOverride selectionOverride = trackSelector.getParameters().getSelectionOverride(rendererTrackIndex, mappedTrackInfo.getTrackGroups(rendererTrackIndex)); // check whether the renderer has been selected before // other renderers should be kept disabled to avoid playback errors if (selectionOverride != null) { parametersBuilder.setRendererDisabled(rendererTrackIndex, false); enabledSomething = true; } } else { parametersBuilder.setRendererDisabled(rendererTrackIndex, true); } } if (enabled && !enabledSomething) { // if nothing has been enabled enable the first sequential renderer parametersBuilder.setRendererDisabled(tracksInfo.rendererTrackIndexes.get(0), false); } trackSelector.setParameters(parametersBuilder); } }
Example 3
Source File: ReactExoplayerView.java From react-native-video with MIT License | 6 votes |
private WritableArray getAudioTrackInfo() { WritableArray audioTracks = Arguments.createArray(); MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo(); int index = getTrackRendererIndex(C.TRACK_TYPE_AUDIO); if (info == null || index == C.INDEX_UNSET) { return audioTracks; } TrackGroupArray groups = info.getTrackGroups(index); for (int i = 0; i < groups.length; ++i) { Format format = groups.get(i).getFormat(0); WritableMap audioTrack = Arguments.createMap(); audioTrack.putInt("index", i); audioTrack.putString("title", format.id != null ? format.id : ""); audioTrack.putString("type", format.sampleMimeType); audioTrack.putString("language", format.language != null ? format.language : ""); audioTrack.putString("bitrate", format.bitrate == Format.NO_VALUE ? "" : String.format(Locale.US, "%.2fMbps", format.bitrate / 1000000f)); audioTracks.pushMap(audioTrack); } return audioTracks; }
Example 4
Source File: ReactExoplayerView.java From react-native-video with MIT License | 6 votes |
private WritableArray getTextTrackInfo() { WritableArray textTracks = Arguments.createArray(); MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo(); int index = getTrackRendererIndex(C.TRACK_TYPE_TEXT); if (info == null || index == C.INDEX_UNSET) { return textTracks; } TrackGroupArray groups = info.getTrackGroups(index); for (int i = 0; i < groups.length; ++i) { Format format = groups.get(i).getFormat(0); WritableMap textTrack = Arguments.createMap(); textTrack.putInt("index", i); textTrack.putString("title", format.id != null ? format.id : ""); textTrack.putString("type", format.sampleMimeType); textTrack.putString("language", format.language != null ? format.language : ""); textTracks.pushMap(textTrack); } return textTracks; }
Example 5
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
/** * Retrieves a list of available tracks * * @return A list of available tracks associated with each type */ @Nullable public Map<RendererType, TrackGroupArray> getAvailableTracks() { if (getPlaybackState() == Player.STATE_IDLE) { return null; } // Retrieves the available tracks Map<RendererType, TrackGroupArray> trackMap = new ArrayMap<>(); MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); if (mappedTrackInfo == null) { return trackMap; } // Maps the available tracks RendererType[] types = new RendererType[]{RendererType.AUDIO, RendererType.VIDEO, RendererType.CLOSED_CAPTION, RendererType.METADATA}; for (RendererType type : types) { List<TrackGroup> trackGroups = new ArrayList<>(); // collect track groups from all the track renderers of the same type for (Integer exoPlayerTrackIndex : getExoPlayerTracksInfo(type, 0, mappedTrackInfo).rendererTrackIndexes) { TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(exoPlayerTrackIndex); for (int i = 0; i < trackGroupArray.length; i++) { trackGroups.add(trackGroupArray.get(i)); } } if (!trackGroups.isEmpty()) { // construct fake track group array for track groups from all the renderers of the same type trackMap.put(type, new TrackGroupArray(trackGroups.toArray(new TrackGroup[trackGroups.size()]))); } } return trackMap; }
Example 6
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
/** * Clear all selected tracks for the specified renderer and re-enable all renderers so the player can select the default track. * * @param type The renderer type */ public void clearSelectedTracks(@NonNull RendererType type) { // Retrieves the available tracks MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo); DefaultTrackSelector.ParametersBuilder parametersBuilder = trackSelector.buildUponParameters(); for (int rendererTrackIndex : tracksInfo.rendererTrackIndexes) { // Reset all renderers re-enabling so the player can select the streams default track. parametersBuilder.setRendererDisabled(rendererTrackIndex, false) .clearSelectionOverrides(rendererTrackIndex); } trackSelector.setParameters(parametersBuilder); }
Example 7
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
/** * Return true if at least one renderer for the given type is enabled * @param type The renderer type * @return true if at least one renderer for the given type is enabled */ public boolean isRendererEnabled(@NonNull RendererType type) { MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo); DefaultTrackSelector.Parameters parameters = trackSelector.getParameters(); for (Integer rendererTrackIndex : tracksInfo.rendererTrackIndexes) { if (!parameters.getRendererDisabled(rendererTrackIndex)) { return true; } } return false; }
Example 8
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
protected ExoPlayerRendererTracksInfo getExoPlayerTracksInfo(@NonNull RendererType type, int groupIndex, MappingTrackSelector.MappedTrackInfo mappedTrackInfo) { // holder for the all exo player renderer track indexes of the specified renderer type List<Integer> exoPlayerRendererTrackIndexes = new ArrayList<>(); // the exoplayer renderer track index related to the specified group index int exoPlayerRendererTrackIndex = C.INDEX_UNSET; // the corrected exoplayer group index int exoPlayerRendererTrackGroupIndex = C.INDEX_UNSET; int skippedRenderersGroupsCount = 0; if (mappedTrackInfo != null) { for (int rendererIndex = 0; rendererIndex < mappedTrackInfo.getRendererCount(); rendererIndex++) { int exoPlayerRendererType = mappedTrackInfo.getRendererType(rendererIndex); if (type == getExoMediaRendererType(exoPlayerRendererType)) { exoPlayerRendererTrackIndexes.add(rendererIndex); TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(rendererIndex); if (skippedRenderersGroupsCount + trackGroups.length > groupIndex) { if (exoPlayerRendererTrackIndex == C.INDEX_UNSET) { // if the groupIndex belongs to the current exo player renderer exoPlayerRendererTrackIndex = rendererIndex; exoPlayerRendererTrackGroupIndex = groupIndex - skippedRenderersGroupsCount; } } else { skippedRenderersGroupsCount += trackGroups.length; } } } } return new ExoPlayerRendererTracksInfo(exoPlayerRendererTrackIndexes, exoPlayerRendererTrackIndex, exoPlayerRendererTrackGroupIndex); }
Example 9
Source File: ReactExoplayerView.java From react-native-video with MIT License | 5 votes |
private WritableArray getVideoTrackInfo() { WritableArray videoTracks = Arguments.createArray(); MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo(); int index = getTrackRendererIndex(C.TRACK_TYPE_VIDEO); if (info == null || index == C.INDEX_UNSET) { return videoTracks; } TrackGroupArray groups = info.getTrackGroups(index); for (int i = 0; i < groups.length; ++i) { TrackGroup group = groups.get(i); for (int trackIndex = 0; trackIndex < group.length; trackIndex++) { Format format = group.getFormat(trackIndex); WritableMap videoTrack = Arguments.createMap(); videoTrack.putInt("width", format.width == Format.NO_VALUE ? 0 : format.width); videoTrack.putInt("height",format.height == Format.NO_VALUE ? 0 : format.height); videoTrack.putInt("bitrate", format.bitrate == Format.NO_VALUE ? 0 : format.bitrate); videoTrack.putString("codecs", format.codecs != null ? format.codecs : ""); videoTrack.putString("trackId", format.id == null ? String.valueOf(trackIndex) : format.id); videoTracks.pushMap(videoTrack); } } return videoTracks; }
Example 10
Source File: ExoPlayerMappedTrackInfo.java From no-player with Apache License 2.0 | 4 votes |
ExoPlayerMappedTrackInfo(MappingTrackSelector.MappedTrackInfo mappedTrackInfo) { this.mappedTrackInfo = mappedTrackInfo; }