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

The following examples show how to use com.google.android.exoplayer2.trackselection.TrackSelection. 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: CompositeTrackSelectorCreator.java    From no-player with Apache License 2.0 6 votes vote down vote up
CompositeTrackSelector create(Options options, DefaultBandwidthMeter bandwidthMeter) {
    TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(
            bandwidthMeter,
            options.minDurationBeforeQualityIncreaseInMillis(),
            AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
            AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION,
            AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
            AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
            Clock.DEFAULT
    );
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
    DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters()
            .setMaxVideoBitrate(options.maxVideoBitrate())
            .build();
    trackSelector.setParameters(trackSelectorParameters);

    ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector);
    ExoPlayerAudioTrackSelector audioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector);
    ExoPlayerVideoTrackSelector videoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector);
    ExoPlayerSubtitleTrackSelector subtitleTrackSelector = new ExoPlayerSubtitleTrackSelector(exoPlayerTrackSelector);
    return new CompositeTrackSelector(trackSelector, audioTrackSelector, videoTrackSelector, subtitleTrackSelector);
}
 
Example #2
Source File: ExoPlayerImpl.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Constructs an instance. Must be called from a thread that has an associated {@link Looper}.
 *
 * @param renderers The {@link Renderer}s that will be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 */
@SuppressLint("HandlerLeak")
public ExoPlayerImpl(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl) {
  Log.i(TAG, "Init " + ExoPlayerLibraryInfo.VERSION + " [" + Util.DEVICE_DEBUG_INFO + "]");
  Assertions.checkState(renderers.length > 0);
  this.renderers = Assertions.checkNotNull(renderers);
  this.trackSelector = Assertions.checkNotNull(trackSelector);
  this.playWhenReady = false;
  this.playbackState = STATE_IDLE;
  this.listeners = new CopyOnWriteArraySet<>();
  emptyTrackSelections = new TrackSelectionArray(new TrackSelection[renderers.length]);
  timeline = Timeline.EMPTY;
  window = new Timeline.Window();
  period = new Timeline.Period();
  trackGroups = TrackGroupArray.EMPTY;
  trackSelections = emptyTrackSelections;
  eventHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
      ExoPlayerImpl.this.handleEvent(msg);
    }
  };
  playbackInfo = new ExoPlayerImplInternal.PlaybackInfo(0, 0);
  internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady,
      eventHandler, playbackInfo, this);
}
 
Example #3
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #4
Source File: SsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private ChunkSampleStream<SsChunkSource> buildSampleStream(TrackSelection selection,
    long positionUs) {
  int streamElementIndex = trackGroups.indexOf(selection.getTrackGroup());
  SsChunkSource chunkSource =
      chunkSourceFactory.createChunkSource(
          manifestLoaderErrorThrower,
          manifest,
          streamElementIndex,
          selection,
          trackEncryptionBoxes,
          transferListener);
  return new ChunkSampleStream<>(
      manifest.streamElements[streamElementIndex].type,
      null,
      null,
      chunkSource,
      this,
      allocator,
      positionUs,
      minLoadableRetryCount,
      eventDispatcher);
}
 
Example #5
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #6
Source File: DownloadHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a {@link DownloadRequest} for downloading the selected tracks. Must not be called until
 * after preparation completes.
 *
 * @param id The unique content id.
 * @param data Application provided data to store in {@link DownloadRequest#data}.
 * @return The built {@link DownloadRequest}.
 */
public DownloadRequest getDownloadRequest(String id, @Nullable byte[] data) {
  if (mediaSource == null) {
    return new DownloadRequest(
        id, downloadType, uri, /* streamKeys= */ Collections.emptyList(), cacheKey, data);
  }
  assertPreparedWithMedia();
  List<StreamKey> streamKeys = new ArrayList<>();
  List<TrackSelection> allSelections = new ArrayList<>();
  int periodCount = trackSelectionsByPeriodAndRenderer.length;
  for (int periodIndex = 0; periodIndex < periodCount; periodIndex++) {
    allSelections.clear();
    int rendererCount = trackSelectionsByPeriodAndRenderer[periodIndex].length;
    for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
      allSelections.addAll(trackSelectionsByPeriodAndRenderer[periodIndex][rendererIndex]);
    }
    streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections));
  }
  return new DownloadRequest(id, downloadType, uri, streamKeys, cacheKey, data);
}
 
Example #7
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
private ChunkSampleStream<DashChunkSource> buildSampleStream(int adaptationSetIndex,
    TrackSelection selection, long positionUs) {
  AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
  int embeddedTrackCount = 0;
  int[] embeddedTrackTypes = new int[2];
  boolean enableEventMessageTrack = hasEventMessageTrack(adaptationSet);
  if (enableEventMessageTrack) {
    embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_METADATA;
  }
  boolean enableCea608Track = hasCea608Track(adaptationSet);
  if (enableCea608Track) {
    embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_TEXT;
  }
  if (embeddedTrackCount < embeddedTrackTypes.length) {
    embeddedTrackTypes = Arrays.copyOf(embeddedTrackTypes, embeddedTrackCount);
  }
  DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(
      manifestLoaderErrorThrower, manifest, periodIndex, adaptationSetIndex, selection,
      elapsedRealtimeOffset, enableEventMessageTrack, enableCea608Track);
  ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(adaptationSet.type,
      embeddedTrackTypes, chunkSource, this, allocator, positionUs, minLoadableRetryCount,
      eventDispatcher);
  return stream;
}
 
Example #8
Source File: ChunkedTrackBlacklistUtil.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Blacklists {@code trackSelectionIndex} in {@code trackSelection} for
 * {@code blacklistDurationMs} if calling {@link #shouldBlacklist(Exception)} for {@code e}
 * returns true. Else does nothing. Note that blacklisting will fail if the track is the only
 * non-blacklisted track in the selection.
 *
 * @param trackSelection The track selection.
 * @param trackSelectionIndex The index in the selection to consider blacklisting.
 * @param e The error to inspect.
 * @param blacklistDurationMs The duration to blacklist the track for, if it is blacklisted.
 * @return Whether the track was blacklisted.
 */
public static boolean maybeBlacklistTrack(TrackSelection trackSelection, int trackSelectionIndex,
    Exception e, long blacklistDurationMs) {
  if (shouldBlacklist(e)) {
    boolean blacklisted = trackSelection.blacklist(trackSelectionIndex, blacklistDurationMs);
    int responseCode = ((InvalidResponseCodeException) e).responseCode;
    if (blacklisted) {
      Log.w(TAG, "Blacklisted: duration=" + blacklistDurationMs + ", responseCode="
          + responseCode + ", format=" + trackSelection.getFormat(trackSelectionIndex));
    } else {
      Log.w(TAG, "Blacklisting failed (cannot blacklist last enabled track): responseCode="
          + responseCode + ", format=" + trackSelection.getFormat(trackSelectionIndex));
    }
    return blacklisted;
  }
  return false;
}
 
Example #9
Source File: ChunkedTrackBlacklistUtil.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Blacklists {@code trackSelectionIndex} in {@code trackSelection} for
 * {@code blacklistDurationMs} if calling {@link #shouldBlacklist(Exception)} for {@code e}
 * returns true. Else does nothing. Note that blacklisting will fail if the track is the only
 * non-blacklisted track in the selection.
 *
 * @param trackSelection The track selection.
 * @param trackSelectionIndex The index in the selection to consider blacklisting.
 * @param e The error to inspect.
 * @param blacklistDurationMs The duration to blacklist the track for, if it is blacklisted.
 * @return Whether the track was blacklisted.
 */
public static boolean maybeBlacklistTrack(TrackSelection trackSelection, int trackSelectionIndex,
    Exception e, long blacklistDurationMs) {
  if (shouldBlacklist(e)) {
    boolean blacklisted = trackSelection.blacklist(trackSelectionIndex, blacklistDurationMs);
    int responseCode = ((InvalidResponseCodeException) e).responseCode;
    if (blacklisted) {
      Log.w(TAG, "Blacklisted: duration=" + blacklistDurationMs + ", responseCode="
          + responseCode + ", format=" + trackSelection.getFormat(trackSelectionIndex));
    } else {
      Log.w(TAG, "Blacklisting failed (cannot blacklist last enabled track): responseCode="
          + responseCode + ", format=" + trackSelection.getFormat(trackSelectionIndex));
    }
    return blacklisted;
  }
  return false;
}
 
Example #10
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param trackEncryptionBoxes Track encryption boxes for the stream.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource,
    TrackEncryptionBox[] trackEncryptionBoxes) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}
 
Example #11
Source File: SsMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  List<StreamKey> streamKeys = new ArrayList<>();
  for (int selectionIndex = 0; selectionIndex < trackSelections.size(); selectionIndex++) {
    TrackSelection trackSelection = trackSelections.get(selectionIndex);
    int streamElementIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
    for (int i = 0; i < trackSelection.length(); i++) {
      streamKeys.add(new StreamKey(streamElementIndex, trackSelection.getIndexInTrackGroup(i)));
    }
  }
  return streamKeys;
}
 
Example #12
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    TrackEncryptionBox[] trackEncryptionBoxes,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
      trackSelection, dataSource, trackEncryptionBoxes);
}
 
Example #13
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void onMediaPrepared() {
  Assertions.checkNotNull(mediaPreparer);
  Assertions.checkNotNull(mediaPreparer.mediaPeriods);
  Assertions.checkNotNull(mediaPreparer.timeline);
  int periodCount = mediaPreparer.mediaPeriods.length;
  int rendererCount = rendererCapabilities.length;
  trackSelectionsByPeriodAndRenderer =
      (List<TrackSelection>[][]) new List<?>[periodCount][rendererCount];
  immutableTrackSelectionsByPeriodAndRenderer =
      (List<TrackSelection>[][]) new List<?>[periodCount][rendererCount];
  for (int i = 0; i < periodCount; i++) {
    for (int j = 0; j < rendererCount; j++) {
      trackSelectionsByPeriodAndRenderer[i][j] = new ArrayList<>();
      immutableTrackSelectionsByPeriodAndRenderer[i][j] =
          Collections.unmodifiableList(trackSelectionsByPeriodAndRenderer[i][j]);
    }
  }
  trackGroupArrays = new TrackGroupArray[periodCount];
  mappedTrackInfos = new MappedTrackInfo[periodCount];
  for (int i = 0; i < periodCount; i++) {
    trackGroupArrays[i] = mediaPreparer.mediaPeriods[i].getTrackGroups();
    TrackSelectorResult trackSelectorResult = runTrackSelection(/* periodIndex= */ i);
    trackSelector.onSelectionActivated(trackSelectorResult.info);
    mappedTrackInfos[i] = Assertions.checkNotNull(trackSelector.getCurrentMappedTrackInfo());
  }
  setPreparedWithMedia();
  Assertions.checkNotNull(callbackHandler)
      .post(() -> Assertions.checkNotNull(callback).onPrepared(this));
}
 
Example #14
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public @NullableType TrackSelection[] createTrackSelections(
    @NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
  @NullableType TrackSelection[] selections = new TrackSelection[definitions.length];
  for (int i = 0; i < definitions.length; i++) {
    selections[i] =
        definitions[i] == null
            ? null
            : new DownloadTrackSelection(definitions[i].group, definitions[i].tracks);
  }
  return selections;
}
 
Example #15
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public List<StreamKey> getStreamKeys(List<TrackSelection> trackSelections) {
  List<StreamKey> streamKeys = new ArrayList<>();
  for (int selectionIndex = 0; selectionIndex < trackSelections.size(); selectionIndex++) {
    TrackSelection trackSelection = trackSelections.get(selectionIndex);
    int streamElementIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
    for (int i = 0; i < trackSelection.length(); i++) {
      streamKeys.add(new StreamKey(streamElementIndex, trackSelection.getIndexInTrackGroup(i)));
    }
  }
  return streamKeys;
}
 
Example #16
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private TrackSelector createTrackSelector(){
    // Create a default TrackSelector
    // Measures bandwidth during playback. Can be null if not required.
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    return trackSelector;
}
 
Example #17
Source File: DefaultSsChunkSource.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest, int elementIndex, TrackSelection trackSelection,
    TrackEncryptionBox[] trackEncryptionBoxes) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
      trackSelection, dataSource, trackEncryptionBoxes);
}
 
Example #18
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    TrackEncryptionBox[] trackEncryptionBoxes =
        format.drmInitData != null ? manifest.protectionElement.trackEncryptionBoxes : null;
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}
 
Example #19
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void releaseOrphanEmbeddedStreams(
    TrackSelection[] selections, SampleStream[] streams, int[] streamIndexToTrackGroupIndex) {
  for (int i = 0; i < selections.length; i++) {
    if (streams[i] instanceof EmptySampleStream || streams[i] instanceof EmbeddedSampleStream) {
      // We need to release an embedded stream if the corresponding primary stream is released.
      int primaryStreamIndex = getPrimaryStreamIndex(i, streamIndexToTrackGroupIndex);
      boolean mayRetainStream;
      if (primaryStreamIndex == C.INDEX_UNSET) {
        // If the corresponding primary stream is not selected, we may retain an existing
        // EmptySampleStream.
        mayRetainStream = streams[i] instanceof EmptySampleStream;
      } else {
        // If the corresponding primary stream is selected, we may retain the embedded stream if
        // the stream's parent still matches.
        mayRetainStream =
            (streams[i] instanceof EmbeddedSampleStream)
                && ((EmbeddedSampleStream) streams[i]).parent == streams[primaryStreamIndex];
      }
      if (!mayRetainStream) {
        if (streams[i] instanceof EmbeddedSampleStream) {
          ((EmbeddedSampleStream) streams[i]).release();
        }
        streams[i] = null;
      }
    }
  }
}
 
Example #20
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(
      manifestLoaderErrorThrower, manifest, elementIndex, trackSelection, dataSource);
}
 
Example #21
Source File: VideoViewActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private void initializePlayer() {


        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //test

        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);

        // 2. Create the player
        mExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

        ////Set media controller
        mPlayerView.setUseController(true);//set to true or false to see controllers
        mPlayerView.requestFocus();
        // Bind the player to the view.
        mPlayerView.setPlayer(mExoPlayer);

        DataSpec dataSpec = new DataSpec(mMediaUri);
        final InputStreamDataSource inputStreamDataSource = new InputStreamDataSource(this, dataSpec);
        try {
            inputStreamDataSource.open(dataSpec);
        } catch (IOException e) {
            e.printStackTrace();
        }

        DataSource.Factory factory = new DataSource.Factory() {

            @Override
            public DataSource createDataSource() {
                return inputStreamDataSource;
            }
        };
        MediaSource audioSource = new ExtractorMediaSource(inputStreamDataSource.getUri(),
                factory, new DefaultExtractorsFactory(), null, null);

        mExoPlayer.prepare(audioSource);
        mExoPlayer.setPlayWhenReady(true); //run file/link when ready to play.

    }
 
Example #22
Source File: ExoPlayerImplInternal.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void notifyTrackSelectionDiscontinuity() {
  MediaPeriodHolder periodHolder = queue.getFrontPeriod();
  while (periodHolder != null) {
    TrackSelectorResult trackSelectorResult = periodHolder.getTrackSelectorResult();
    if (trackSelectorResult != null) {
      TrackSelection[] trackSelections = trackSelectorResult.selections.getAll();
      for (TrackSelection trackSelection : trackSelections) {
        if (trackSelection != null) {
          trackSelection.onDiscontinuity();
        }
      }
    }
    periodHolder = periodHolder.getNext();
  }
}
 
Example #23
Source File: MediaPeriodHolder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void enableTrackSelectionsInResult(TrackSelectorResult trackSelectorResult) {
  for (int i = 0; i < trackSelectorResult.length; i++) {
    boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
    TrackSelection trackSelection = trackSelectorResult.selections.get(i);
    if (rendererEnabled && trackSelection != null) {
      trackSelection.enable();
    }
  }
}
 
Example #24
Source File: MediaPeriodHolder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void disableTrackSelectionsInResult(TrackSelectorResult trackSelectorResult) {
  for (int i = 0; i < trackSelectorResult.length; i++) {
    boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
    TrackSelection trackSelection = trackSelectorResult.selections.get(i);
    if (rendererEnabled && trackSelection != null) {
      trackSelection.disable();
    }
  }
}
 
Example #25
Source File: DeferredMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
    SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
  if (preparePositionOverrideUs != C.TIME_UNSET && positionUs == preparePositionUs) {
    positionUs = preparePositionOverrideUs;
    preparePositionOverrideUs = C.TIME_UNSET;
  }
  return mediaPeriod.selectTracks(selections, mayRetainStreamFlags, streams, streamResetFlags,
      positionUs);
}
 
Example #26
Source File: ClippingMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
    SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
  sampleStreams = new ClippingSampleStream[streams.length];
  SampleStream[] childStreams = new SampleStream[streams.length];
  for (int i = 0; i < streams.length; i++) {
    sampleStreams[i] = (ClippingSampleStream) streams[i];
    childStreams[i] = sampleStreams[i] != null ? sampleStreams[i].childStream : null;
  }
  long enablePositionUs =
      mediaPeriod.selectTracks(
          selections, mayRetainStreamFlags, childStreams, streamResetFlags, positionUs);
  pendingInitialDiscontinuityPositionUs =
      isPendingInitialDiscontinuity()
              && positionUs == startUs
              && shouldKeepInitialDiscontinuity(startUs, selections)
          ? enablePositionUs
          : C.TIME_UNSET;
  Assertions.checkState(
      enablePositionUs == positionUs
          || (enablePositionUs >= startUs
              && (endUs == C.TIME_END_OF_SOURCE || enablePositionUs <= endUs)));
  for (int i = 0; i < streams.length; i++) {
    if (childStreams[i] == null) {
      sampleStreams[i] = null;
    } else if (streams[i] == null || sampleStreams[i].childStream != childStreams[i]) {
      sampleStreams[i] = new ClippingSampleStream(childStreams[i]);
    }
    streams[i] = sampleStreams[i];
  }
  return enablePositionUs;
}
 
Example #27
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    TrackEncryptionBox[] trackEncryptionBoxes,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
      trackSelection, dataSource, trackEncryptionBoxes);
}
 
Example #28
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
    SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
  int[] streamIndexToTrackGroupIndex = getStreamIndexToTrackGroupIndex(selections);
  releaseDisabledStreams(selections, mayRetainStreamFlags, streams);
  releaseOrphanEmbeddedStreams(selections, streams, streamIndexToTrackGroupIndex);
  selectNewStreams(
      selections, streams, streamResetFlags, positionUs, streamIndexToTrackGroupIndex);

  ArrayList<ChunkSampleStream<DashChunkSource>> sampleStreamList = new ArrayList<>();
  ArrayList<EventSampleStream> eventSampleStreamList = new ArrayList<>();
  for (SampleStream sampleStream : streams) {
    if (sampleStream instanceof ChunkSampleStream) {
      @SuppressWarnings("unchecked")
      ChunkSampleStream<DashChunkSource> stream =
          (ChunkSampleStream<DashChunkSource>) sampleStream;
      sampleStreamList.add(stream);
    } else if (sampleStream instanceof EventSampleStream) {
      eventSampleStreamList.add((EventSampleStream) sampleStream);
    }
  }
  sampleStreams = newSampleStreamArray(sampleStreamList.size());
  sampleStreamList.toArray(sampleStreams);
  eventSampleStreams = new EventSampleStream[eventSampleStreamList.size()];
  eventSampleStreamList.toArray(eventSampleStreams);

  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  return positionUs;
}
 
Example #29
Source File: MediaPeriodHolder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void enableTrackSelectionsInResult() {
  TrackSelectorResult trackSelectorResult = this.trackSelectorResult;
  if (!isLoadingMediaPeriod() || trackSelectorResult == null) {
    return;
  }
  for (int i = 0; i < trackSelectorResult.length; i++) {
    boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
    TrackSelection trackSelection = trackSelectorResult.selections.get(i);
    if (rendererEnabled && trackSelection != null) {
      trackSelection.enable();
    }
  }
}
 
Example #30
Source File: VideoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public VideoPlayer() {
    mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER));

    mainHandler = new Handler();

    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    lastReportedPlaybackState = ExoPlayer.STATE_IDLE;
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying);
}