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

The following examples show how to use com.google.android.exoplayer2.trackselection.FixedTrackSelection. 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: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: PlayerContainerView.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
public void setVideoUrl(String url) {
    mVideoUrl = url;
    boolean needNewPlayer = mPlayer == null;
    if (needNewPlayer) {
        TrackSelection.Factory trackSelectionFactory = new FixedTrackSelection.Factory();
        mTrackSelector = new DefaultTrackSelector(trackSelectionFactory);

        mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), mTrackSelector);
        mPlayer.addListener(this);

        mPlayerView.setPlayer(mPlayer);
        mPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
    }

    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(),
            Util.getUserAgent(getContext(), "unknown"), null);
    // Produces Extractor instances for parsing the media data.
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    // This is the MediaSource representing the media to be played.
    MediaSource videoSource = new ExtractorMediaSource(Uri.parse(url),
            dataSourceFactory, extractorsFactory, null, null);
    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource);
    // Prepare the player with the source.
    mPlayer.prepare(loopingMediaSource);
    mPlayer.setVolume(0);
    mPlayerView.requestFocus();
    mPlayer.setPlayWhenReady(true); // autoplay
}
 
Example #3
Source File: QueuedExoPlayer.java    From Jockey with Apache License 2.0 4 votes vote down vote up
public QueuedExoPlayer(Context context) {
    mContext = context;
    mState = ExoPlayerState.IDLE;
    mQueue = Collections.emptyList();

    mSourceFactory = new DefaultDataSourceFactory(mContext, USER_AGENT);
    mExtractorsFactory = new DefaultExtractorsFactory();

    RenderersFactory renderersFactory = new DefaultRenderersFactory(mContext);
    TrackSelector trackSelector = new DefaultTrackSelector(new FixedTrackSelection.Factory());
    LoadControl loadControl = new DefaultLoadControl();
    SimpleExoPlayer baseInstance = ExoPlayerFactory.newSimpleInstance(
            renderersFactory, trackSelector, loadControl);
    mExoPlayer = new EqualizedExoPlayer(context, baseInstance);

    mExoPlayer.addListener(new Player.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 onRepeatModeChanged(int repeatMode) {
            Timber.i("onRepeatModeChanged (%d)", repeatMode);
        }

        @Override
        public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
            Timber.i("onShuffleModeEnabledChanged (%b)", shuffleModeEnabled);
        }

        @Override
        public void onTimelineChanged(Timeline timeline, Object manifest) {
            Timber.i("onTimelineChanged");
            dispatchDurationUpdateIfNeeded();
        }

        @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(int reason) {
            Timber.i("onPositionDiscontinuity");
            QueuedExoPlayer.this.onPositionDiscontinuity(reason);
        }

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
            Timber.i("onPlaybackParametersChanged");
        }

        @Override
        public void onSeekProcessed() {
            Timber.i("okSeekProcessed");
        }
    });
}