Java Code Examples for com.google.android.exoplayer2.util.Util#areEqual()

The following examples show how to use com.google.android.exoplayer2.util.Util#areEqual() . 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: AudioFocusManager.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets audio attributes that should be used to manage audio focus.
 *
 * @param audioAttributes The audio attributes or {@code null} if audio focus should not be
 *     managed automatically.
 * @param playWhenReady The current state of {@link ExoPlayer#getPlayWhenReady()}.
 * @param playerState The current player state; {@link ExoPlayer#getPlaybackState()}.
 * @return A {@link PlayerCommand} to execute on the player.
 */
@PlayerCommand
public int setAudioAttributes(
    @Nullable AudioAttributes audioAttributes, boolean playWhenReady, int playerState) {
  if (!Util.areEqual(this.audioAttributes, audioAttributes)) {
    this.audioAttributes = audioAttributes;
    focusGain = convertAudioAttributesToFocusGain(audioAttributes);

    Assertions.checkArgument(
        focusGain == C.AUDIOFOCUS_GAIN || focusGain == C.AUDIOFOCUS_NONE,
        "Automatic handling of audio focus is only available for USAGE_MEDIA and USAGE_GAME.");
    if (playWhenReady
        && (playerState == Player.STATE_BUFFERING || playerState == Player.STATE_READY)) {
      return requestAudioFocus();
    }
  }

  return playerState == Player.STATE_IDLE
      ? handleIdle(playWhenReady)
      : handlePrepare(playWhenReady);
}
 
Example 2
Source File: SimpleExoPlayer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) {
  verifyApplicationThread();
  if (!Util.areEqual(this.audioAttributes, audioAttributes)) {
    this.audioAttributes = audioAttributes;
    for (Renderer renderer : renderers) {
      if (renderer.getTrackType() == C.TRACK_TYPE_AUDIO) {
        player
            .createMessage(renderer)
            .setType(C.MSG_SET_AUDIO_ATTRIBUTES)
            .setPayload(audioAttributes)
            .send();
      }
    }
    for (AudioListener audioListener : audioListeners) {
      audioListener.onAudioAttributesChanged(audioAttributes);
    }
  }

  @AudioFocusManager.PlayerCommand
  int playerCommand =
      audioFocusManager.setAudioAttributes(
          handleAudioFocus ? audioAttributes : null, getPlayWhenReady(), getPlaybackState());
  updatePlayWhenReady(getPlayWhenReady(), playerCommand);
}
 
Example 3
Source File: CompositeMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/** Updates the event dispatcher and returns whether the event should be dispatched. */
private boolean maybeUpdateEventDispatcher(
    int childWindowIndex, @Nullable MediaPeriodId childMediaPeriodId) {
  MediaPeriodId mediaPeriodId = null;
  if (childMediaPeriodId != null) {
    mediaPeriodId = getMediaPeriodIdForChildMediaPeriodId(id, childMediaPeriodId);
    if (mediaPeriodId == null) {
      // Media period not found. Ignore event.
      return false;
    }
  }
  int windowIndex = getWindowIndexForChildWindowIndex(id, childWindowIndex);
  if (eventDispatcher.windowIndex != windowIndex
      || !Util.areEqual(eventDispatcher.mediaPeriodId, mediaPeriodId)) {
    eventDispatcher =
        createEventDispatcher(windowIndex, mediaPeriodId, /* mediaTimeOffsetMs= */ 0);
  }
  return true;
}
 
Example 4
Source File: DrmInitData.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  DrmInitData other = (DrmInitData) obj;
  return Util.areEqual(schemeType, other.schemeType)
      && Arrays.equals(schemeDatas, other.schemeDatas);
}
 
Example 5
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static boolean formatsMatch(Format manifestFormat, Format sampleFormat) {
  String manifestFormatMimeType = manifestFormat.sampleMimeType;
  String sampleFormatMimeType = sampleFormat.sampleMimeType;
  int manifestFormatTrackType = MimeTypes.getTrackType(manifestFormatMimeType);
  if (manifestFormatTrackType != C.TRACK_TYPE_TEXT) {
    return manifestFormatTrackType == MimeTypes.getTrackType(sampleFormatMimeType);
  } else if (!Util.areEqual(manifestFormatMimeType, sampleFormatMimeType)) {
    return false;
  }
  if (MimeTypes.APPLICATION_CEA608.equals(manifestFormatMimeType)
      || MimeTypes.APPLICATION_CEA708.equals(manifestFormatMimeType)) {
    return manifestFormat.accessibilityChannel == sampleFormat.accessibilityChannel;
  }
  return true;
}
 
Example 6
Source File: UrlLinkFrame.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  UrlLinkFrame other = (UrlLinkFrame) obj;
  return id.equals(other.id) && Util.areEqual(description, other.description)
      && Util.areEqual(url, other.url);
}
 
Example 7
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isSupportedAdaptiveVideoTrack(
    Format format,
    @Nullable String mimeType,
    int formatSupport,
    int requiredAdaptiveSupport,
    int maxVideoWidth,
    int maxVideoHeight,
    int maxVideoBitrate) {
  return isSupported(formatSupport, false) && ((formatSupport & requiredAdaptiveSupport) != 0)
      && (mimeType == null || Util.areEqual(format.sampleMimeType, mimeType))
      && (format.width == Format.NO_VALUE || format.width <= maxVideoWidth)
      && (format.height == Format.NO_VALUE || format.height <= maxVideoHeight)
      && (format.bitrate == Format.NO_VALUE || format.bitrate <= maxVideoBitrate);
}
 
Example 8
Source File: GeobFrame.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  GeobFrame other = (GeobFrame) obj;
  return Util.areEqual(mimeType, other.mimeType) && Util.areEqual(filename, other.filename)
      && Util.areEqual(description, other.description) && Arrays.equals(data, other.data);
}
 
Example 9
Source File: CommentFrame.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  CommentFrame other = (CommentFrame) obj;
  return Util.areEqual(description, other.description) && Util.areEqual(language, other.language)
      && Util.areEqual(text, other.text);
}
 
Example 10
Source File: Descriptor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  Descriptor other = (Descriptor) obj;
  return Util.areEqual(schemeIdUri, other.schemeIdUri) && Util.areEqual(value, other.value)
      && Util.areEqual(id, other.id);
}
 
Example 11
Source File: ProgressiveDownloadAction.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
  if (this == o) {
    return true;
  }
  if (!super.equals(o)) {
    return false;
  }
  ProgressiveDownloadAction that = (ProgressiveDownloadAction) o;
  return Util.areEqual(customCacheKey, that.customCacheKey);
}
 
Example 12
Source File: InternalFrame.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  InternalFrame other = (InternalFrame) obj;
  return Util.areEqual(description, other.description)
      && Util.areEqual(domain, other.domain)
      && Util.areEqual(text, other.text);
}
 
Example 13
Source File: Descriptor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  Descriptor other = (Descriptor) obj;
  return Util.areEqual(schemeIdUri, other.schemeIdUri) && Util.areEqual(value, other.value)
      && Util.areEqual(id, other.id);
}
 
Example 14
Source File: PrivFrame.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  PrivFrame other = (PrivFrame) obj;
  return Util.areEqual(owner, other.owner) && Arrays.equals(privateData, other.privateData);
}
 
Example 15
Source File: GeobFrame.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || getClass() != obj.getClass()) {
    return false;
  }
  GeobFrame other = (GeobFrame) obj;
  return Util.areEqual(mimeType, other.mimeType) && Util.areEqual(filename, other.filename)
      && Util.areEqual(description, other.description) && Arrays.equals(data, other.data);
}
 
Example 16
Source File: ConcatenatingMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object getUidOfPeriod(int periodIndex) {
  Object uid = timeline.getUidOfPeriod(periodIndex);
  return Util.areEqual(uid, replacedId) ? DUMMY_ID : uid;
}
 
Example 17
Source File: HlsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void buildAndPrepareAudioSampleStreamWrappers(
    long positionUs,
    List<Rendition> audioRenditions,
    List<HlsSampleStreamWrapper> sampleStreamWrappers,
    List<int[]> manifestUrlsIndicesPerWrapper,
    Map<String, DrmInitData> overridingDrmInitData) {
  ArrayList<Uri> scratchPlaylistUrls =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Format> scratchPlaylistFormats =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  ArrayList<Integer> scratchIndicesList =
      new ArrayList<>(/* initialCapacity= */ audioRenditions.size());
  HashSet<String> alreadyGroupedNames = new HashSet<>();
  for (int renditionByNameIndex = 0;
      renditionByNameIndex < audioRenditions.size();
      renditionByNameIndex++) {
    String name = audioRenditions.get(renditionByNameIndex).name;
    if (!alreadyGroupedNames.add(name)) {
      // This name already has a corresponding group.
      continue;
    }

    boolean renditionsHaveCodecs = true;
    scratchPlaylistUrls.clear();
    scratchPlaylistFormats.clear();
    scratchIndicesList.clear();
    // Group all renditions with matching name.
    for (int renditionIndex = 0; renditionIndex < audioRenditions.size(); renditionIndex++) {
      if (Util.areEqual(name, audioRenditions.get(renditionIndex).name)) {
        Rendition rendition = audioRenditions.get(renditionIndex);
        scratchIndicesList.add(renditionIndex);
        scratchPlaylistUrls.add(rendition.url);
        scratchPlaylistFormats.add(rendition.format);
        renditionsHaveCodecs &= rendition.format.codecs != null;
      }
    }

    HlsSampleStreamWrapper sampleStreamWrapper =
        buildSampleStreamWrapper(
            C.TRACK_TYPE_AUDIO,
            scratchPlaylistUrls.toArray(new Uri[0]),
            scratchPlaylistFormats.toArray(new Format[0]),
            /* muxedAudioFormat= */ null,
            /* muxedCaptionFormats= */ Collections.emptyList(),
            overridingDrmInitData,
            positionUs);
    manifestUrlsIndicesPerWrapper.add(Util.toArray(scratchIndicesList));
    sampleStreamWrappers.add(sampleStreamWrapper);

    if (allowChunklessPreparation && renditionsHaveCodecs) {
      Format[] renditionFormats = scratchPlaylistFormats.toArray(new Format[0]);
      sampleStreamWrapper.prepareWithMasterPlaylistInfo(
          new TrackGroupArray(new TrackGroup(renditionFormats)), 0, TrackGroupArray.EMPTY);
    }
  }
}
 
Example 18
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Overrides the track selection for the renderer at the specified index.
 *
 * <p>When the {@link TrackGroupArray} mapped to the renderer matches the one provided, the
 * override is applied. When the {@link TrackGroupArray} does not match, the override has no
 * effect. The override replaces any previous override for the specified {@link TrackGroupArray}
 * for the specified {@link Renderer}.
 *
 * <p>Passing a {@code null} override will cause the renderer to be disabled when the {@link
 * TrackGroupArray} mapped to it matches the one provided. When the {@link TrackGroupArray} does
 * not match a {@code null} override has no effect. Hence a {@code null} override differs from
 * disabling the renderer using {@link #setRendererDisabled(int, boolean)} because the renderer
 * is disabled conditionally on the {@link TrackGroupArray} mapped to it, where-as {@link
 * #setRendererDisabled(int, boolean)} disables the renderer unconditionally.
 *
 * <p>To remove overrides use {@link #clearSelectionOverride(int, TrackGroupArray)}, {@link
 * #clearSelectionOverrides(int)} or {@link #clearSelectionOverrides()}.
 *
 * @param rendererIndex The renderer index.
 * @param groups The {@link TrackGroupArray} for which the override should be applied.
 * @param override The override.
 * @return This builder.
 */
public final ParametersBuilder setSelectionOverride(
    int rendererIndex, TrackGroupArray groups, SelectionOverride override) {
  Map<TrackGroupArray, SelectionOverride> overrides = selectionOverrides.get(rendererIndex);
  if (overrides == null) {
    overrides = new HashMap<>();
    selectionOverrides.put(rendererIndex, overrides);
  }
  if (overrides.containsKey(groups) && Util.areEqual(overrides.get(groups), override)) {
    // The override is unchanged.
    return this;
  }
  overrides.put(groups, override);
  return this;
}
 
Example 19
Source File: TrackSelectorResult.java    From K-Sonic with MIT License 3 votes vote down vote up
/**
 * Returns whether this result is equivalent to {@code other} for the renderer at the given index.
 * The results are equivalent if they have equal track selections and configurations for the
 * renderer.
 *
 * @param other The other {@link TrackSelectorResult}. May be null, in which case {@code false}
 *     will be returned in all cases.
 * @param index The renderer index to check for equivalence.
 * @return Whether this result is equivalent to {@code other} for all renderers.
 */
public boolean isEquivalent(TrackSelectorResult other, int index) {
  if (other == null) {
    return false;
  }
  return Util.areEqual(selections.get(index), other.selections.get(index))
      && Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index]);
}
 
Example 20
Source File: TrackSelectorResult.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Returns whether this result is equivalent to {@code other} for the renderer at the given index.
 * The results are equivalent if they have equal track selections and configurations for the
 * renderer.
 *
 * @param other The other {@link TrackSelectorResult}. May be null, in which case {@code false}
 *     will be returned.
 * @param index The renderer index to check for equivalence.
 * @return Whether this result is equivalent to {@code other} for the renderer at the specified
 *     index.
 */
public boolean isEquivalent(@Nullable TrackSelectorResult other, int index) {
  if (other == null) {
    return false;
  }
  return Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index])
      && Util.areEqual(selections.get(index), other.selections.get(index));
}