Java Code Examples for com.google.android.exoplayer2.trackselection.TrackSelection#getFormat()

The following examples show how to use com.google.android.exoplayer2.trackselection.TrackSelection#getFormat() . 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: ExoPlayerImplInternal.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static Format[] getFormats(TrackSelection newSelection) {
  // Build an array of formats contained by the selection.
  int length = newSelection != null ? newSelection.length() : 0;
  Format[] formats = new Format[length];
  for (int i = 0; i < length; i++) {
    formats[i] = newSelection.getFormat(i);
  }
  return formats;
}
 
Example 2
Source File: ExoPlayerImplInternal.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@NonNull
private static Format[] getFormats(TrackSelection newSelection) {
  // Build an array of formats contained by the selection.
  int length = newSelection != null ? newSelection.length() : 0;
  Format[] formats = new Format[length];
  for (int i = 0; i < length; i++) {
    formats[i] = newSelection.getFormat(i);
  }
  return formats;
}
 
Example 3
Source File: ExoPlayerImplInternal.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@NonNull
private static Format[] getFormats(TrackSelection newSelection) {
  // Build an array of formats contained by the selection.
  int length = newSelection != null ? newSelection.length() : 0;
  Format[] formats = new Format[length];
  for (int i = 0; i < length; i++) {
    formats[i] = newSelection.getFormat(i);
  }
  return formats;
}
 
Example 4
Source File: ExoVideoView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
private void updateForCurrentTrackSelections() {
    if (player == null) {
        return;
    }
    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
            // onRenderedFirstFrame().
            hideArtwork();
            return;
        }
    }
    // Video disabled so the shutter must be closed.
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }
    // Display artwork if enabled and available, else hide it.
    if (useArtwork) {
        for (int i = 0; i < selections.length; i++) {
            TrackSelection selection = selections.get(i);
            if (selection != null) {
                for (int j = 0; j < selection.length(); j++) {
                    Metadata metadata = selection.getFormat(j).metadata;
                    if (metadata != null && setArtworkFromMetadata(metadata)) {
                        return;
                    }
                }
            }
        }
        if (setArtworkFromBitmap(defaultArtwork)) {
            return;
        }
    }
    // Artwork disabled or unavailable.
    hideArtwork();
}
 
Example 5
Source File: SimpleExoPlayerView.java    From K-Sonic with MIT License 5 votes vote down vote up
private void updateForCurrentTrackSelections() {
  if (player == null) {
    return;
  }
  TrackSelectionArray selections = player.getCurrentTrackSelections();
  for (int i = 0; i < selections.length; i++) {
    if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
      // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
      // onRenderedFirstFrame().
      hideArtwork();
      return;
    }
  }
  // Video disabled so the shutter must be closed.
  if (shutterView != null) {
    shutterView.setVisibility(VISIBLE);
  }
  // Display artwork if enabled and available, else hide it.
  if (useArtwork) {
    for (int i = 0; i < selections.length; i++) {
      TrackSelection selection = selections.get(i);
      if (selection != null) {
        for (int j = 0; j < selection.length(); j++) {
          Metadata metadata = selection.getFormat(j).metadata;
          if (metadata != null && setArtworkFromMetadata(metadata)) {
            return;
          }
        }
      }
    }
    if (setArtworkFromBitmap(defaultArtwork)) {
      return;
    }
  }
  // Artwork disabled or unavailable.
  hideArtwork();
}
 
Example 6
Source File: ExoPlayerImplInternal.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static Format[] getFormats(TrackSelection newSelection) {
  // Build an array of formats contained by the selection.
  int length = newSelection != null ? newSelection.length() : 0;
  Format[] formats = new Format[length];
  for (int i = 0; i < length; i++) {
    formats[i] = newSelection.getFormat(i);
  }
  return formats;
}
 
Example 7
Source File: ExoPlayerImplInternal.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static Format[] getFormats(TrackSelection newSelection) {
  // Build an array of formats contained by the selection.
  int length = newSelection != null ? newSelection.length() : 0;
  Format[] formats = new Format[length];
  for (int i = 0; i < length; i++) {
    formats[i] = newSelection.getFormat(i);
  }
  return formats;
}
 
Example 8
Source File: CustomizePlayerView.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private void updateForCurrentTrackSelections(boolean isNewPlayer) {
    if (player == null || player.getCurrentTrackGroups().isEmpty()) {
        if (!keepContentOnPlayerReset) {
            hideArtwork();
            closeShutter();
        }
        return;
    }

    if (isNewPlayer && !keepContentOnPlayerReset) {
        closeShutter();
    }

    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            hideArtwork();
            return;
        }
    }

    closeShutter();
    if (useArtwork) {
        for (int i = 0; i < selections.length; i++) {
            TrackSelection selection = selections.get(i);
            if (selection != null) {
                for (int j = 0; j < selection.length(); j++) {
                    Metadata metadata = selection.getFormat(j).metadata;
                    if (metadata != null && setArtworkFromMetadata(metadata)) {
                        return;
                    }
                }
            }
        }
        if (setArtworkFromBitmap(defaultArtwork)) {
            return;
        }
    }
    // Artwork disabled or unavailable.
    hideArtwork();
}
 
Example 9
Source File: ExoPlayerImplInternal.java    From K-Sonic with MIT License 4 votes vote down vote up
private void enableRenderers(boolean[] rendererWasEnabledFlags, int enabledRendererCount)
    throws ExoPlaybackException {
  enabledRenderers = new Renderer[enabledRendererCount];
  enabledRendererCount = 0;
  for (int i = 0; i < renderers.length; i++) {
    Renderer renderer = renderers[i];
    TrackSelection newSelection = playingPeriodHolder.trackSelectorResult.selections.get(i);
    if (newSelection != null) {
      enabledRenderers[enabledRendererCount++] = renderer;
      if (renderer.getState() == Renderer.STATE_DISABLED) {
        RendererConfiguration rendererConfiguration =
            playingPeriodHolder.trackSelectorResult.rendererConfigurations[i];
        // The renderer needs enabling with its new track selection.
        boolean playing = playWhenReady && state == ExoPlayer.STATE_READY;
        // Consider as joining only if the renderer was previously disabled.
        boolean joining = !rendererWasEnabledFlags[i] && playing;
        // Build an array of formats contained by the selection.
        Format[] formats = new Format[newSelection.length()];
        for (int j = 0; j < formats.length; j++) {
          formats[j] = newSelection.getFormat(j);
        }
        // Enable the renderer.
        renderer.enable(rendererConfiguration, formats, playingPeriodHolder.sampleStreams[i],
            rendererPositionUs, joining, playingPeriodHolder.getRendererOffset());
        MediaClock mediaClock = renderer.getMediaClock();
        if (mediaClock != null) {
          if (rendererMediaClock != null) {
            throw ExoPlaybackException.createForUnexpected(
                new IllegalStateException("Multiple renderer media clocks enabled."));
          }
          rendererMediaClock = mediaClock;
          rendererMediaClockSource = renderer;
        }
        // Start the renderer if playing.
        if (playing) {
          renderer.start();
        }
      }
    }
  }
}