com.google.android.exoplayer2.trackselection.MappingTrackSelector Java Examples

The following examples show how to use com.google.android.exoplayer2.trackselection.MappingTrackSelector. 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: ReactExoplayerView.java    From react-native-video with MIT License 6 votes vote down vote up
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 #2
Source File: ReactExoplayerView.java    From react-native-video with MIT License 6 votes vote down vote up
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 #3
Source File: ExoMediaPlayer.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void initPlayer() {
    mInternalPlayer = new SimpleExoPlayer.Builder(
            mAppContext,
            mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory,
            mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector,
            mLoadControl == null ? mLoadControl = new DefaultLoadControl() : mLoadControl,
            DefaultBandwidthMeter.getSingletonInstance(mAppContext),
            Util.getLooper(),
            new AnalyticsCollector(Clock.DEFAULT),
            /* useLazyPreparation= */ true,
            Clock.DEFAULT)
            .build();
    setOptions();

    //播放器日志
    if (VideoViewManager.getConfig().mIsEnableLog && mTrackSelector instanceof MappingTrackSelector) {
        mInternalPlayer.addAnalyticsListener(new EventLogger((MappingTrackSelector) mTrackSelector, "ExoPlayer"));
    }

    mInternalPlayer.addListener(this);
    mInternalPlayer.addVideoListener(this);
}
 
Example #4
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: EventLogger.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 * @param tag The tag used for logging.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
  this.trackSelector = trackSelector;
  this.tag = tag;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #7
Source File: EventLogger.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 * @param tag The tag used for logging.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
  this.trackSelector = trackSelector;
  this.tag = tag;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #8
Source File: EventLogger.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 * @param tag The tag used for logging.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
  this.trackSelector = trackSelector;
  this.tag = tag;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #9
Source File: EventLogger.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();

  listeners = new CopyOnWriteArrayList<>();
}
 
Example #10
Source File: ReactExoplayerView.java    From react-native-video with MIT License 5 votes vote down vote up
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 #11
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #14
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #15
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface,
    MappingTrackSelector trackSelector,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  SimpleExoPlayer player = new DebugSimpleExoPlayer(host, trackSelector,
      new DefaultLoadControl(), drmSessionManager);
  player.setVideoSurface(surface);
  return player;
}
 
Example #16
Source File: ExoHostedTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface,
    MappingTrackSelector trackSelector,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(host, trackSelector,
      new DefaultLoadControl(), drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF,
      0);
  player.setVideoSurface(surface);
  return player;
}
 
Example #17
Source File: TrackSelectionHelper.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Shows the selection dialog for a given renderer.
     *
     * @param activity      The parent activity.
     * @param title         The dialog's title.
     * @param trackSelector The current track selector.
     * @param rendererIndex The index of the renderer.
     */
    public void showSelectionDialog(Activity activity, CharSequence title, MappingTrackSelector trackSelector,
                                    int rendererIndex) {
        this.trackInfo = trackSelector.getCurrentMappedTrackInfo();
        this.rendererIndex = rendererIndex;

        trackGroups = trackInfo.getTrackGroups(rendererIndex);
        trackGroupsAdaptive = new boolean[trackGroups.length];
        for (int i = 0; i < trackGroups.length; i++) {
            trackGroupsAdaptive[i] = adaptiveVideoTrackSelectionFactory != null
                    && this.trackInfo.getAdaptiveSupport(rendererIndex, i, false)
                    != RendererCapabilities.ADAPTIVE_NOT_SUPPORTED
                    && trackGroups.get(i).length > 1;
        }

        TrackGroupArray rendererTrackGroups = this.trackInfo.getTrackGroups(rendererIndex);
//    MappingTrackSelector.Parameters selectionParameters = trackSelector.getParameters();
//    isDisabled = selectionParameters.getRendererDisabled(rendererIndex);
//    override = selectionParameters.getSelectionOverride(rendererIndex, rendererTrackGroups);
//    overrides = override == null ? Collections.emptyList() : Collections.singletonList(override);

//    isDisabled = selector.getRendererDisabled(rendererIndex);
//    override = selector.getSelectionOverride(rendererIndex, trackGroups);

        AlertDialog.Builder builder = new AlertDialog.Builder(activity, themeHelper.getDialogStyle());
        builder.setTitle(title)
                .setView(buildView(LayoutInflater.from(builder.getContext())))
                .setPositiveButton(android.R.string.ok, this)
                .setNegativeButton(android.R.string.cancel, null)
                .create()
                .show();
    }
 
Example #18
Source File: EventLogger.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #19
Source File: EventLogger.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #20
Source File: Action.java    From ExoPlayer-Offline with Apache License 2.0 4 votes vote down vote up
@Override
protected void doActionImpl(ExoPlayer player, MappingTrackSelector trackSelector) {
  player.seekTo(positionMs);
}
 
Example #21
Source File: TrackSelectionHelper.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param selector                           The track selector.
 * @param adaptiveVideoTrackSelectionFactory A factory for adaptive video {@link TrackSelection}s,
 *                                           or null if the selection helper should not support adaptive video.
 */
public TrackSelectionHelper(MappingTrackSelector selector, TrackSelection.Factory adaptiveVideoTrackSelectionFactory, ThemeHelper themeHelper) {
    this.selector = selector;
    this.adaptiveVideoTrackSelectionFactory = adaptiveVideoTrackSelectionFactory;
    this.themeHelper = themeHelper;
}
 
Example #22
Source File: EventLogger.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #23
Source File: TrackSelectionHelper.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param selector The track selector.
 * @param adaptiveTrackSelectionFactory A factory for adaptive {@link TrackSelection}s, or null
 *     if the selection helper should not support adaptive tracks.
 */
public TrackSelectionHelper(MappingTrackSelector selector,
    TrackSelection.Factory adaptiveTrackSelectionFactory) {
  this.selector = selector;
  this.adaptiveTrackSelectionFactory = adaptiveTrackSelectionFactory;
}
 
Example #24
Source File: EventLogger.java    From TubiPlayer with MIT License 4 votes vote down vote up
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
    this.trackSelector = trackSelector;
    window = new Timeline.Window();
    period = new Timeline.Period();
    startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #25
Source File: EventLogger.java    From ExoPlayer-Offline with Apache License 2.0 4 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #26
Source File: TrackSelectionHelper.java    From ExoPlayer-Offline with Apache License 2.0 4 votes vote down vote up
/**
 * @param selector The track selector.
 * @param adaptiveVideoTrackSelectionFactory A factory for adaptive video {@link TrackSelection}s,
 *     or null if the selection helper should not support adaptive video.
 */
public TrackSelectionHelper(MappingTrackSelector selector,
    TrackSelection.Factory adaptiveVideoTrackSelectionFactory) {
  this.selector = selector;
  this.adaptiveVideoTrackSelectionFactory = adaptiveVideoTrackSelectionFactory;
}
 
Example #27
Source File: EventLogger.java    From TigerVideo with Apache License 2.0 4 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
    this.trackSelector = trackSelector;
    window = new Timeline.Window();
    period = new Timeline.Period();
    startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #28
Source File: ExoPlayerMappedTrackInfo.java    From no-player with Apache License 2.0 4 votes vote down vote up
ExoPlayerMappedTrackInfo(MappingTrackSelector.MappedTrackInfo mappedTrackInfo) {
    this.mappedTrackInfo = mappedTrackInfo;
}
 
Example #29
Source File: EventLogger.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
    this.trackSelector = trackSelector;
    window = new Timeline.Window();
    period = new Timeline.Period();
    startTimeMs = SystemClock.elapsedRealtime();
}
 
Example #30
Source File: IjkExo2MediaPlayer.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public MappingTrackSelector getTrackSelector() {
    return mTrackSelector;
}