@Override protected TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports) throws ExoPlaybackException { Assertions.checkState(rendererCapabilities[VIDEO_RENDERER_INDEX].getTrackType() == C.TRACK_TYPE_VIDEO); Assertions.checkState(rendererCapabilities[AUDIO_RENDERER_INDEX].getTrackType() == C.TRACK_TYPE_AUDIO); Assertions.checkState(rendererTrackGroupArrays[VIDEO_RENDERER_INDEX].length == 1); Assertions.checkState(rendererTrackGroupArrays[AUDIO_RENDERER_INDEX].length == 1); TrackSelection[] selections = new TrackSelection[rendererCapabilities.length]; selections[VIDEO_RENDERER_INDEX] = new RandomTrackSelection( rendererTrackGroupArrays[VIDEO_RENDERER_INDEX].get(0), getVideoTrackIndices(rendererTrackGroupArrays[VIDEO_RENDERER_INDEX].get(0), rendererFormatSupports[VIDEO_RENDERER_INDEX][0], videoFormatIds, canIncludeAdditionalVideoFormats), 0 /* seed */); selections[AUDIO_RENDERER_INDEX] = new FixedTrackSelection( rendererTrackGroupArrays[AUDIO_RENDERER_INDEX].get(0), getTrackIndex(rendererTrackGroupArrays[AUDIO_RENDERER_INDEX].get(0), audioFormatId)); includedAdditionalVideoFormats = selections[VIDEO_RENDERER_INDEX].length() > videoFormatIds.length; return selections; }
public void setSelectedTrack(@NonNull RendererType type, int index) { // Retrieves the available tracks int exoPlayerTrackIndex = getExoPlayerTrackType(type); MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); TrackGroupArray trackGroupArray = mappedTrackInfo == null ? null : mappedTrackInfo.getTrackGroups(exoPlayerTrackIndex); if (trackGroupArray == null || trackGroupArray.length == 0) { return; } // Creates the track selection override int[] tracks = new int[] {index}; TrackSelection.Factory factory = tracks.length == 1 ? new FixedTrackSelection.Factory() : adaptiveTrackSelectionFactory; MappingTrackSelector.SelectionOverride selectionOverride = new MappingTrackSelector.SelectionOverride(factory, exoPlayerTrackIndex, tracks); // Specifies the correct track to use trackSelector.setSelectionOverride(exoPlayerTrackIndex, trackGroupArray, selectionOverride); }
ExoPlayerTwoImpl create(Context context, DrmSessionCreator drmSessionCreator, boolean downgradeSecureDecoder) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(context, "user-agent", bandwidthMeter); MediaSourceFactory mediaSourceFactory = new MediaSourceFactory(defaultDataSourceFactory, handler); TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); MediaCodecSelector mediaCodecSelector = downgradeSecureDecoder ? SecurityDowngradingCodecSelector.newInstance() : MediaCodecSelector.DEFAULT; ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector); FixedTrackSelection.Factory trackSelectionFactory = new FixedTrackSelection.Factory(); ExoPlayerAudioTrackSelector exoPlayerAudioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector, trackSelectionFactory); ExoPlayerVideoTrackSelector exoPlayerVideoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector, trackSelectionFactory); ExoPlayerSubtitleTrackSelector exoPlayerSubtitleTrackSelector = new ExoPlayerSubtitleTrackSelector( exoPlayerTrackSelector, trackSelectionFactory ); ExoPlayerCreator exoPlayerCreator = new ExoPlayerCreator(context, trackSelector); RendererTypeRequesterCreator rendererTypeRequesterCreator = new RendererTypeRequesterCreator(); ExoPlayerFacade exoPlayerFacade = new ExoPlayerFacade( mediaSourceFactory, exoPlayerAudioTrackSelector, exoPlayerSubtitleTrackSelector, exoPlayerVideoTrackSelector, exoPlayerCreator, rendererTypeRequesterCreator); PlayerListenersHolder listenersHolder = new PlayerListenersHolder(); ExoPlayerForwarder exoPlayerForwarder = new ExoPlayerForwarder(); LoadTimeout loadTimeout = new LoadTimeout(new SystemClock(), handler); Heart heart = Heart.newInstance(handler); return new ExoPlayerTwoImpl( exoPlayerFacade, listenersHolder, exoPlayerForwarder, loadTimeout, heart, drmSessionCreator, mediaCodecSelector ); }
@Provides static TrackSelection.Factory provideTrackSelectionFactory() { return new FixedTrackSelection.Factory(); }
public QueuedExoPlayer(Context context) { mContext = context; mState = ExoPlayerState.IDLE; mQueue = Collections.emptyList(); TrackSelector trackSelector = new DefaultTrackSelector(new FixedTrackSelection.Factory()); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer baseInstance = ExoPlayerFactory.newSimpleInstance(mContext, trackSelector, loadControl); mExoPlayer = new EqualizedExoPlayer(context, baseInstance); mExoPlayer.addListener(new ExoPlayer.EventListener() { @Override public void onLoadingChanged(boolean isLoading) { Timber.i("onLoadingChanged (%b)", isLoading); } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { Timber.i("onPlayerStateChanged"); QueuedExoPlayer.this.onPlayerStateChanged(playbackState); } @Override public void onTimelineChanged(Timeline timeline, Object manifest) { Timber.i("onTimelineChanged"); QueuedExoPlayer.this.onTimelineChanged(); } @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { Timber.i("onTracksChanged"); } @Override public void onPlayerError(ExoPlaybackException error) { Timber.i("onPlayerError"); QueuedExoPlayer.this.onPlayerError(error); } @Override public void onPositionDiscontinuity() { Timber.i("onPositionDiscontinuity"); QueuedExoPlayer.this.onPositionDiscontinuity(); } }); }