use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class PlayerActivity method updateButtonVisibilities.
// User controls
private void updateButtonVisibilities() {
debugRootView.removeAllViews();
retryButton.setVisibility(needRetrySource ? View.VISIBLE : View.GONE);
debugRootView.addView(retryButton);
if (player == null) {
return;
}
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
if (mappedTrackInfo == null) {
return;
}
for (int i = 0; i < mappedTrackInfo.length; i++) {
TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i);
if (trackGroups.length != 0) {
Button button = new Button(this);
int label;
switch(player.getRendererType(i)) {
case C.TRACK_TYPE_AUDIO:
label = R.string.audio;
break;
case C.TRACK_TYPE_VIDEO:
label = R.string.video;
break;
case C.TRACK_TYPE_TEXT:
label = R.string.text;
break;
default:
continue;
}
button.setText(label);
button.setTag(i);
button.setOnClickListener(this);
debugRootView.addView(button, debugRootView.getChildCount() - 1);
}
}
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class PlayerActivity method onTracksChanged.
@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);
}
}
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project LeafPic by HoraApps.
the class PlayerActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(org.horaapps.leafpic.R.menu.menu_video_player, menu);
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
if (player != null && mappedTrackInfo != null) {
for (int i = 0; i < mappedTrackInfo.length; i++) {
TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i);
if (trackGroups.length != 0) {
switch(player.getRendererType(i)) {
case C.TRACK_TYPE_AUDIO:
menu.findItem(R.id.audio_stuff).setVisible(true);
audio = i;
break;
case C.TRACK_TYPE_VIDEO:
menu.findItem(R.id.video_stuff).setVisible(true);
video = i;
break;
case C.TRACK_TYPE_TEXT:
menu.findItem(R.id.text_stuff).setVisible(true);
text = i;
break;
}
}
}
}
return true;
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class DownloadHelper method onMediaPrepared.
// Initialization of array of Lists.
@SuppressWarnings("unchecked")
private void onMediaPrepared() {
checkNotNull(mediaPreparer);
checkNotNull(mediaPreparer.mediaPeriods);
checkNotNull(mediaPreparer.timeline);
int periodCount = mediaPreparer.mediaPeriods.length;
int rendererCount = rendererCapabilities.length;
trackSelectionsByPeriodAndRenderer = (List<ExoTrackSelection>[][]) new List<?>[periodCount][rendererCount];
immutableTrackSelectionsByPeriodAndRenderer = (List<ExoTrackSelection>[][]) 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] = checkNotNull(trackSelector.getCurrentMappedTrackInfo());
}
setPreparedWithMedia();
checkNotNull(callbackHandler).post(() -> checkNotNull(callback).onPrepared(this));
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class DownloadHelper method addAudioLanguagesToSelection.
/**
* Convenience method to add selections of tracks for all specified audio languages. If an audio
* track in one of the specified languages is not available, the default fallback audio track is
* used instead. Must not be called until after preparation completes.
*
* @param languages A list of audio languages for which tracks should be added to the download
* selection, as IETF BCP 47 conformant tags.
*/
public void addAudioLanguagesToSelection(String... languages) {
assertPreparedWithMedia();
for (int periodIndex = 0; periodIndex < mappedTrackInfos.length; periodIndex++) {
DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT.buildUpon();
MappedTrackInfo mappedTrackInfo = mappedTrackInfos[periodIndex];
int rendererCount = mappedTrackInfo.getRendererCount();
for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
if (mappedTrackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_AUDIO) {
parametersBuilder.setRendererDisabled(rendererIndex, /* disabled= */
true);
}
}
for (String language : languages) {
parametersBuilder.setPreferredAudioLanguage(language);
addTrackSelection(periodIndex, parametersBuilder.build());
}
}
}
Aggregations