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

The following examples show how to use com.google.android.exoplayer2.trackselection.TrackSelectionArray. 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: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("ReferenceEquality")
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    if (trackGroups != lastSeenTrackGroupArray) {
        MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
        if (mappedTrackInfo != null) {
            if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO)
                    == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
                showToast(R.string.error_unsupported_video);
            }
            if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO)
                    == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
                showToast(R.string.error_unsupported_audio);
            }
        }
        lastSeenTrackGroupArray = trackGroups;
    }
}
 
Example #2
Source File: PlaybackStatsListener.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies the tracker that the track selection for the current playback changed.
 *
 * @param eventTime The {@link EventTime}.
 * @param trackSelections The new {@link TrackSelectionArray}.
 */
public void onTracksChanged(EventTime eventTime, TrackSelectionArray trackSelections) {
  boolean videoEnabled = false;
  boolean audioEnabled = false;
  for (TrackSelection trackSelection : trackSelections.getAll()) {
    if (trackSelection != null && trackSelection.length() > 0) {
      int trackType = MimeTypes.getTrackType(trackSelection.getFormat(0).sampleMimeType);
      if (trackType == C.TRACK_TYPE_VIDEO) {
        videoEnabled = true;
      } else if (trackType == C.TRACK_TYPE_AUDIO) {
        audioEnabled = true;
      }
    }
  }
  if (!videoEnabled) {
    maybeUpdateVideoFormat(eventTime, /* newFormat= */ null);
  }
  if (!audioEnabled) {
    maybeUpdateAudioFormat(eventTime, /* newFormat= */ null);
  }
}
 
Example #3
Source File: DefaultLoadControl.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculate target buffer size in bytes based on the selected tracks. The player will try not to
 * exceed this target buffer. Only used when {@code targetBufferBytes} is {@link C#LENGTH_UNSET}.
 *
 * @param renderers The renderers for which the track were selected.
 * @param trackSelectionArray The selected tracks.
 * @return The target buffer size in bytes.
 */
protected int calculateTargetBufferSize(
    Renderer[] renderers, TrackSelectionArray trackSelectionArray) {
  int targetBufferSize = 0;
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectionArray.get(i) != null) {
      targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType());
    }
  }
  return targetBufferSize;
}
 
Example #4
Source File: MediaPeriodHolder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public long applyTrackSelection(
    long positionUs, boolean forceRecreateStreams, boolean[] streamResetFlags) {
  for (int i = 0; i < trackSelectorResult.length; i++) {
    mayRetainStreamFlags[i] =
        !forceRecreateStreams && trackSelectorResult.isEquivalent(periodTrackSelectorResult, i);
  }

  // Undo the effect of previous call to associate no-sample renderers with empty tracks
  // so the mediaPeriod receives back whatever it sent us before.
  disassociateNoSampleRenderersWithEmptySampleStream(sampleStreams);
  updatePeriodTrackSelectorResult(trackSelectorResult);
  // Disable streams on the period and get new streams for updated/newly-enabled tracks.
  TrackSelectionArray trackSelections = trackSelectorResult.selections;
  positionUs =
      mediaPeriod.selectTracks(
          trackSelections.getAll(),
          mayRetainStreamFlags,
          sampleStreams,
          streamResetFlags,
          positionUs);
  associateNoSampleRenderersWithEmptySampleStream(sampleStreams);

  // Update whether we have enabled tracks and sanity check the expected streams are non-null.
  hasEnabledTracks = false;
  for (int i = 0; i < sampleStreams.length; i++) {
    if (sampleStreams[i] != null) {
      Assertions.checkState(trackSelectorResult.isRendererEnabled(i));
      // hasEnabledTracks should be true only when non-empty streams exists.
      if (rendererCapabilities[i].getTrackType() != C.TRACK_TYPE_NONE) {
        hasEnabledTracks = true;
      }
    } else {
      Assertions.checkState(trackSelections.get(i) == null);
    }
  }
  return positionUs;
}
 
Example #5
Source File: DefaultLoadControl.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups,
    TrackSelectionArray trackSelections) {
  hasVideo = hasVideo(renderers, trackSelections);
  targetBufferSize =
      targetBufferBytesOverwrite == C.LENGTH_UNSET
          ? calculateTargetBufferSize(renderers, trackSelections)
          : targetBufferBytesOverwrite;
  allocator.setTargetBufferSize(targetBufferSize);
}
 
Example #6
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
	updateButtonVisibilities();
	MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
	if (mappedTrackInfo != null) {
		if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO)
			== MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
			showToast(R.string.error_unsupported_video);
		}
		if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO)
			== MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
			showToast(R.string.error_unsupported_audio);
		}
	}
}
 
Example #7
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 5 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
  if (mappedTrackInfo != null) {
    if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO)
            == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
      showToast(R.string.error_unsupported_video);
    }
    if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO)
            == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
      showToast(R.string.error_unsupported_audio);
    }
  }
}
 
Example #8
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void onTracksChanged(
    TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  EventTime eventTime = generatePlayingMediaPeriodEventTime();
  for (AnalyticsListener listener : listeners) {
    listener.onTracksChanged(eventTime, trackGroups, trackSelections);
  }
}
 
Example #9
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 5 votes vote down vote up
/**
 * ExoPlayer Player.EventListener methods
 */
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    if (mExoPlayerListener != null) {
        mExoPlayerListener.onTracksChanged(
                mPlayer.getCurrentWindowIndex(),
                getNextWindowIndex(),
                mPlayer.getPlaybackState() == Player.STATE_READY);
    }
}
 
Example #10
Source File: MediaPeriodHolder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public long applyTrackSelection(
    long positionUs, boolean forceRecreateStreams, boolean[] streamResetFlags) {
  for (int i = 0; i < trackSelectorResult.length; i++) {
    mayRetainStreamFlags[i] =
        !forceRecreateStreams && trackSelectorResult.isEquivalent(periodTrackSelectorResult, i);
  }

  // Undo the effect of previous call to associate no-sample renderers with empty tracks
  // so the mediaPeriod receives back whatever it sent us before.
  disassociateNoSampleRenderersWithEmptySampleStream(sampleStreams);
  updatePeriodTrackSelectorResult(trackSelectorResult);
  // Disable streams on the period and get new streams for updated/newly-enabled tracks.
  TrackSelectionArray trackSelections = trackSelectorResult.selections;
  positionUs =
      mediaPeriod.selectTracks(
          trackSelections.getAll(),
          mayRetainStreamFlags,
          sampleStreams,
          streamResetFlags,
          positionUs);
  associateNoSampleRenderersWithEmptySampleStream(sampleStreams);

  // Update whether we have enabled tracks and sanity check the expected streams are non-null.
  hasEnabledTracks = false;
  for (int i = 0; i < sampleStreams.length; i++) {
    if (sampleStreams[i] != null) {
      Assertions.checkState(trackSelectorResult.isRendererEnabled(i));
      // hasEnabledTracks should be true only when non-empty streams exists.
      if (rendererCapabilities[i].getTrackType() != C.TRACK_TYPE_NONE) {
        hasEnabledTracks = true;
      }
    } else {
      Assertions.checkState(trackSelections.get(i) == null);
    }
  }
  return positionUs;
}
 
Example #11
Source File: DefaultLoadControl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups,
    TrackSelectionArray trackSelections) {
  targetBufferSize =
      targetBufferBytesOverwrite == C.LENGTH_UNSET
          ? calculateTargetBufferSize(renderers, trackSelections)
          : targetBufferBytesOverwrite;
  allocator.setTargetBufferSize(targetBufferSize);
}
 
Example #12
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void onTracksChanged(
    TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  EventTime eventTime = generatePlayingMediaPeriodEventTime();
  for (AnalyticsListener listener : listeners) {
    listener.onTracksChanged(eventTime, trackGroups, trackSelections);
  }
}
 
Example #13
Source File: DefaultLoadControl.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups,
    TrackSelectionArray trackSelections) {
  targetBufferSize = 0;
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelections.get(i) != null) {
      targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType());
    }
  }
  allocator.setTargetBufferSize(targetBufferSize);
}
 
Example #14
Source File: DefaultLoadControl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculate target buffer size in bytes based on the selected tracks. The player will try not to
 * exceed this target buffer. Only used when {@code targetBufferBytes} is {@link C#LENGTH_UNSET}.
 *
 * @param renderers The renderers for which the track were selected.
 * @param trackSelectionArray The selected tracks.
 * @return The target buffer size in bytes.
 */
protected int calculateTargetBufferSize(
    Renderer[] renderers, TrackSelectionArray trackSelectionArray) {
  int targetBufferSize = 0;
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectionArray.get(i) != null) {
      targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType());
    }
  }
  return targetBufferSize;
}
 
Example #15
Source File: AnalyticsCollector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void onTracksChanged(
    TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  EventTime eventTime = generatePlayingMediaPeriodEventTime();
  for (AnalyticsListener listener : listeners) {
    listener.onTracksChanged(eventTime, trackGroups, trackSelections);
  }
}
 
Example #16
Source File: ExoPlayerImplInternal.java    From K-Sonic with MIT License 5 votes vote down vote up
public long updatePeriodTrackSelection(long positionUs, boolean forceRecreateStreams,
    boolean[] streamResetFlags) {
  TrackSelectionArray trackSelections = trackSelectorResult.selections;
  for (int i = 0; i < trackSelections.length; i++) {
    mayRetainStreamFlags[i] = !forceRecreateStreams
        && trackSelectorResult.isEquivalent(periodTrackSelectorResult, i);
  }

  // Disable streams on the period and get new streams for updated/newly-enabled tracks.
  positionUs = mediaPeriod.selectTracks(trackSelections.getAll(), mayRetainStreamFlags,
      sampleStreams, streamResetFlags, positionUs);
  periodTrackSelectorResult = trackSelectorResult;

  // Update whether we have enabled tracks and sanity check the expected streams are non-null.
  hasEnabledTracks = false;
  for (int i = 0; i < sampleStreams.length; i++) {
    if (sampleStreams[i] != null) {
      Assertions.checkState(trackSelections.get(i) != null);
      hasEnabledTracks = true;
    } else {
      Assertions.checkState(trackSelections.get(i) == null);
    }
  }

  // The track selection has changed.
  loadControl.onTracksSelected(renderers, trackSelectorResult.groups, trackSelections);
  return positionUs;
}
 
Example #17
Source File: DefaultLoadControl.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static boolean hasVideo(Renderer[] renderers, TrackSelectionArray trackSelectionArray) {
  for (int i = 0; i < renderers.length; i++) {
    if (renderers[i].getTrackType() == C.TRACK_TYPE_VIDEO && trackSelectionArray.get(i) != null) {
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: DefaultLoadControl.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate target buffer size in bytes based on the selected tracks. The player will try not to
 * exceed this target buffer. Only used when {@code targetBufferBytes} is {@link C#LENGTH_UNSET}.
 *
 * @param renderers The renderers for which the track were selected.
 * @param trackSelectionArray The selected tracks.
 * @return The target buffer size in bytes.
 */
protected int calculateTargetBufferSize(
    Renderer[] renderers, TrackSelectionArray trackSelectionArray) {
  int targetBufferSize = 0;
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectionArray.get(i) != null) {
      targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType());
    }
  }
  return targetBufferSize;
}
 
Example #19
Source File: DefaultLoadControl.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups,
    TrackSelectionArray trackSelections) {
  hasVideo = hasVideo(renderers, trackSelections);
  targetBufferSize =
      targetBufferBytesOverwrite == C.LENGTH_UNSET
          ? calculateTargetBufferSize(renderers, trackSelections)
          : targetBufferBytesOverwrite;
  allocator.setTargetBufferSize(targetBufferSize);
}
 
Example #20
Source File: PlaybackStatsListener.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onTracksChanged(
    EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  sessionManager.updateSessions(eventTime);
  for (String session : playbackStatsTrackers.keySet()) {
    if (sessionManager.belongsToSession(eventTime, session)) {
      playbackStatsTrackers.get(session).onTracksChanged(eventTime, trackSelections);
    }
  }
}
 
Example #21
Source File: EventInfoForwarder.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    HashMap<String, String> callingMethodParameters = new HashMap<>();

    callingMethodParameters.put(Parameters.TRACK_GROUPS, String.valueOf(trackGroups));
    callingMethodParameters.put(Parameters.TRACK_SELECTIONS, String.valueOf(trackSelections));

    infoListener.onNewInfo(Methods.ON_TRACKS_CHANGED, callingMethodParameters);
}
 
Example #22
Source File: AnalyticsCollector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public final void onTracksChanged(
    TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  EventTime eventTime = generatePlayingMediaPeriodEventTime();
  for (AnalyticsListener listener : listeners) {
    listener.onTracksChanged(eventTime, trackGroups, trackSelections);
  }
}
 
Example #23
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    updateButtonVisibilities();
    MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
    if (mappedTrackInfo != null) {
        if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO)
                == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
            showToast(R.string.error_unsupported_video);
        }
        if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO)
                == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
            showToast(R.string.error_unsupported_audio);
        }
    }
}
 
Example #24
Source File: DefaultLoadControl.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculate target buffer size in bytes based on the selected tracks. The player will try not to
 * exceed this target buffer. Only used when {@code targetBufferBytes} is {@link C#LENGTH_UNSET}.
 *
 * @param renderers The renderers for which the track were selected.
 * @param trackSelectionArray The selected tracks.
 * @return The target buffer size in bytes.
 */
protected int calculateTargetBufferSize(
    Renderer[] renderers, TrackSelectionArray trackSelectionArray) {
  int targetBufferSize = 0;
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectionArray.get(i) != null) {
      targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType());
    }
  }
  return targetBufferSize;
}
 
Example #25
Source File: ExoMediaPlayer.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onTracksChanged(final TrackGroupArray trackGroups,
                            final TrackSelectionArray trackSelections) {
    if (Log.logDEnabled()) {
        Log.d(TAG, "onTracksChanged()");
    }
}
 
Example #26
Source File: OnPrepareForwarder.java    From no-player with Apache License 2.0 4 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    // TODO: should we send?
}
 
Example #27
Source File: EventListener.java    From no-player with Apache License 2.0 4 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    for (Player.EventListener listener : listeners) {
        listener.onTracksChanged(trackGroups, trackSelections);
    }
}
 
Example #28
Source File: TokPlayer.java    From Tok-Android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    if (mOnVideoPlayerListener != null) {
        mOnVideoPlayerListener.onTracksChanged(trackGroups, trackSelections);
    }
}
 
Example #29
Source File: Alarmio.java    From Alarmio with Apache License 2.0 4 votes vote down vote up
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
 
Example #30
Source File: ExoPlayerImpl.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public TrackSelectionArray getCurrentTrackSelections() {
  return playbackInfo.trackSelectorResult.selections;
}