Java Code Examples for com.google.android.exoplayer2.util.UriUtil#resolveToUri()

The following examples show how to use com.google.android.exoplayer2.util.UriUtil#resolveToUri() . 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: HlsDownloader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void addSegment(
    HlsMediaPlaylist mediaPlaylist,
    HlsMediaPlaylist.Segment segment,
    HashSet<Uri> seenEncryptionKeyUris,
    ArrayList<Segment> out) {
  String baseUri = mediaPlaylist.baseUri;
  long startTimeUs = mediaPlaylist.startTimeUs + segment.relativeStartTimeUs;
  if (segment.fullSegmentEncryptionKeyUri != null) {
    Uri keyUri = UriUtil.resolveToUri(baseUri, segment.fullSegmentEncryptionKeyUri);
    if (seenEncryptionKeyUris.add(keyUri)) {
      out.add(new Segment(startTimeUs, SegmentDownloader.getCompressibleDataSpec(keyUri)));
    }
  }
  Uri segmentUri = UriUtil.resolveToUri(baseUri, segment.url);
  DataSpec dataSpec =
      new DataSpec(segmentUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
  out.add(new Segment(startTimeUs, dataSpec));
}
 
Example 2
Source File: HlsDownloader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void addSegment(
    HlsMediaPlaylist mediaPlaylist,
    HlsMediaPlaylist.Segment segment,
    HashSet<Uri> seenEncryptionKeyUris,
    ArrayList<Segment> out) {
  String baseUri = mediaPlaylist.baseUri;
  long startTimeUs = mediaPlaylist.startTimeUs + segment.relativeStartTimeUs;
  if (segment.fullSegmentEncryptionKeyUri != null) {
    Uri keyUri = UriUtil.resolveToUri(baseUri, segment.fullSegmentEncryptionKeyUri);
    if (seenEncryptionKeyUris.add(keyUri)) {
      out.add(new Segment(startTimeUs, SegmentDownloader.getCompressibleDataSpec(keyUri)));
    }
  }
  Uri segmentUri = UriUtil.resolveToUri(baseUri, segment.url);
  DataSpec dataSpec =
      new DataSpec(segmentUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
  out.add(new Segment(startTimeUs, dataSpec));
}
 
Example 3
Source File: HlsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static void addSegment(
    ArrayList<Segment> segments,
    HlsMediaPlaylist mediaPlaylist,
    HlsMediaPlaylist.Segment hlsSegment,
    HashSet<Uri> seenEncryptionKeyUris) {
  long startTimeUs = mediaPlaylist.startTimeUs + hlsSegment.relativeStartTimeUs;
  if (hlsSegment.fullSegmentEncryptionKeyUri != null) {
    Uri keyUri = UriUtil.resolveToUri(mediaPlaylist.baseUri,
        hlsSegment.fullSegmentEncryptionKeyUri);
    if (seenEncryptionKeyUris.add(keyUri)) {
      segments.add(new Segment(startTimeUs, new DataSpec(keyUri)));
    }
  }
  Uri resolvedUri = UriUtil.resolveToUri(mediaPlaylist.baseUri, hlsSegment.url);
  segments.add(new Segment(startTimeUs,
      new DataSpec(resolvedUri, hlsSegment.byterangeOffset, hlsSegment.byterangeLength, null)));
}
 
Example 4
Source File: HlsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static void addSegment(
    ArrayList<Segment> segments,
    HlsMediaPlaylist mediaPlaylist,
    HlsMediaPlaylist.Segment hlsSegment,
    HashSet<Uri> seenEncryptionKeyUris) {
  long startTimeUs = mediaPlaylist.startTimeUs + hlsSegment.relativeStartTimeUs;
  if (hlsSegment.fullSegmentEncryptionKeyUri != null) {
    Uri keyUri = UriUtil.resolveToUri(mediaPlaylist.baseUri,
        hlsSegment.fullSegmentEncryptionKeyUri);
    if (seenEncryptionKeyUris.add(keyUri)) {
      segments.add(new Segment(startTimeUs, new DataSpec(keyUri)));
    }
  }
  Uri resolvedUri = UriUtil.resolveToUri(mediaPlaylist.baseUri, hlsSegment.url);
  segments.add(new Segment(startTimeUs,
      new DataSpec(resolvedUri, hlsSegment.byterangeOffset, hlsSegment.byterangeLength, null)));
}
 
Example 5
Source File: HlsDownloader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void addSegment(
    HlsMediaPlaylist mediaPlaylist,
    HlsMediaPlaylist.Segment segment,
    HashSet<Uri> seenEncryptionKeyUris,
    ArrayList<Segment> out) {
  String baseUri = mediaPlaylist.baseUri;
  long startTimeUs = mediaPlaylist.startTimeUs + segment.relativeStartTimeUs;
  if (segment.fullSegmentEncryptionKeyUri != null) {
    Uri keyUri = UriUtil.resolveToUri(baseUri, segment.fullSegmentEncryptionKeyUri);
    if (seenEncryptionKeyUris.add(keyUri)) {
      out.add(new Segment(startTimeUs, SegmentDownloader.getCompressibleDataSpec(keyUri)));
    }
  }
  Uri segmentUri = UriUtil.resolveToUri(baseUri, segment.url);
  DataSpec dataSpec =
      new DataSpec(segmentUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
  out.add(new Segment(startTimeUs, dataSpec));
}
 
Example 6
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public MediaPlaylistBundle(HlsUrl playlistUrl) {
  this.playlistUrl = playlistUrl;
  mediaPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MediaPlaylist");
  mediaPlaylistLoadable =
      new ParsingLoadable<>(
          dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST),
          UriUtil.resolveToUri(masterPlaylist.baseUri, playlistUrl.url),
          C.DATA_TYPE_MANIFEST,
          playlistParser);
}
 
Example 7
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DataSpec getDataSpec() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
  return new DataSpec(
      chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
}
 
Example 8
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Nullable
private static Uri getFullEncryptionKeyUri(HlsMediaPlaylist playlist, @Nullable Segment segment) {
  if (segment == null || segment.fullSegmentEncryptionKeyUri == null) {
    return null;
  }
  return UriUtil.resolveToUri(playlist.baseUri, segment.fullSegmentEncryptionKeyUri);
}
 
Example 9
Source File: SsManifest.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Builds a uri for requesting the specified chunk of the specified track.
 *
 * @param track The index of the track for which to build the URL.
 * @param chunkIndex The index of the chunk for which to build the URL.
 * @return The request uri.
 */
public Uri buildRequestUri(int track, int chunkIndex) {
  Assertions.checkState(formats != null);
  Assertions.checkState(chunkStartTimes != null);
  Assertions.checkState(chunkIndex < chunkStartTimes.size());
  String bitrateString = Integer.toString(formats[track].bitrate);
  String startTimeString = chunkStartTimes.get(chunkIndex).toString();
  String chunkUrl = chunkTemplate
      .replace(URL_PLACEHOLDER_BITRATE_1, bitrateString)
      .replace(URL_PLACEHOLDER_BITRATE_2, bitrateString)
      .replace(URL_PLACEHOLDER_START_TIME_1, startTimeString)
      .replace(URL_PLACEHOLDER_START_TIME_2, startTimeString);
  return UriUtil.resolveToUri(baseUri, chunkUrl);
}
 
Example 10
Source File: HlsPlaylistTracker.java    From K-Sonic with MIT License 5 votes vote down vote up
public MediaPlaylistBundle(HlsUrl playlistUrl, long initialLastSnapshotAccessTimeMs) {
  this.playlistUrl = playlistUrl;
  lastSnapshotAccessTimeMs = initialLastSnapshotAccessTimeMs;
  mediaPlaylistLoader = new Loader("HlsPlaylistTracker:MediaPlaylist");
  mediaPlaylistLoadable = new ParsingLoadable<>(
      dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST),
      UriUtil.resolveToUri(masterPlaylist.baseUri, playlistUrl.url), C.DATA_TYPE_MANIFEST,
      playlistParser);
}
 
Example 11
Source File: SsManifest.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a uri for requesting the specified chunk of the specified track.
 *
 * @param track The index of the track for which to build the URL.
 * @param chunkIndex The index of the chunk for which to build the URL.
 * @return The request uri.
 */
public Uri buildRequestUri(int track, int chunkIndex) {
  Assertions.checkState(formats != null);
  Assertions.checkState(chunkStartTimes != null);
  Assertions.checkState(chunkIndex < chunkStartTimes.size());
  String bitrateString = Integer.toString(formats[track].bitrate);
  String startTimeString = chunkStartTimes.get(chunkIndex).toString();
  String chunkUrl = chunkTemplate
      .replace(URL_PLACEHOLDER_BITRATE_1, bitrateString)
      .replace(URL_PLACEHOLDER_BITRATE_2, bitrateString)
      .replace(URL_PLACEHOLDER_START_TIME_1, startTimeString)
      .replace(URL_PLACEHOLDER_START_TIME_2, startTimeString);
  return UriUtil.resolveToUri(baseUri, chunkUrl);
}
 
Example 12
Source File: HlsMediaPlaylistSegmentIterator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DataSpec getDataSpec() {
  checkInBounds();
  HlsMediaPlaylist.Segment segment = playlist.segments.get((int) getCurrentIndex());
  Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
  return new DataSpec(
      chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
}
 
Example 13
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public MediaPlaylistBundle(HlsUrl playlistUrl) {
  this.playlistUrl = playlistUrl;
  mediaPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MediaPlaylist");
  mediaPlaylistLoadable =
      new ParsingLoadable<>(
          dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST),
          UriUtil.resolveToUri(masterPlaylist.baseUri, playlistUrl.url),
          C.DATA_TYPE_MANIFEST,
          playlistParser);
}
 
Example 14
Source File: SsManifest.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a uri for requesting the specified chunk of the specified track.
 *
 * @param track The index of the track for which to build the URL.
 * @param chunkIndex The index of the chunk for which to build the URL.
 * @return The request uri.
 */
public Uri buildRequestUri(int track, int chunkIndex) {
  Assertions.checkState(formats != null);
  Assertions.checkState(chunkStartTimes != null);
  Assertions.checkState(chunkIndex < chunkStartTimes.size());
  String bitrateString = Integer.toString(formats[track].bitrate);
  String startTimeString = chunkStartTimes.get(chunkIndex).toString();
  String chunkUrl = chunkTemplate
      .replace(URL_PLACEHOLDER_BITRATE_1, bitrateString)
      .replace(URL_PLACEHOLDER_BITRATE_2, bitrateString)
      .replace(URL_PLACEHOLDER_START_TIME_1, startTimeString)
      .replace(URL_PLACEHOLDER_START_TIME_2, startTimeString);
  return UriUtil.resolveToUri(baseUri, chunkUrl);
}
 
Example 15
Source File: SsManifest.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a uri for requesting the specified chunk of the specified track.
 *
 * @param track The index of the track for which to build the URL.
 * @param chunkIndex The index of the chunk for which to build the URL.
 * @return The request uri.
 */
public Uri buildRequestUri(int track, int chunkIndex) {
  Assertions.checkState(formats != null);
  Assertions.checkState(chunkStartTimes != null);
  Assertions.checkState(chunkIndex < chunkStartTimes.size());
  String bitrateString = Integer.toString(formats[track].bitrate);
  String startTimeString = chunkStartTimes.get(chunkIndex).toString();
  String chunkUrl = chunkTemplate
      .replace(URL_PLACEHOLDER_BITRATE_1, bitrateString)
      .replace(URL_PLACEHOLDER_BITRATE_2, bitrateString)
      .replace(URL_PLACEHOLDER_START_TIME_1, startTimeString)
      .replace(URL_PLACEHOLDER_START_TIME_2, startTimeString);
  return UriUtil.resolveToUri(baseUri, chunkUrl);
}
 
Example 16
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public DataSpec getDataSpec() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
  return new DataSpec(
      chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
}
 
Example 17
Source File: RangedUri.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the resolved {@link Uri} represented by the instance.
 *
 * @param baseUri The base Uri.
 * @return The {@link Uri} represented by the instance.
 */
public Uri resolveUri(String baseUri) {
  return UriUtil.resolveToUri(baseUri, referenceUri);
}
 
Example 18
Source File: RangedUri.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the resolved {@link Uri} represented by the instance.
 *
 * @param baseUri The base Uri.
 * @return The {@link Uri} represented by the instance.
 */
public Uri resolveUri(String baseUri) {
  return UriUtil.resolveToUri(baseUri, referenceUri);
}
 
Example 19
Source File: RangedUri.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the resolved {@link Uri} represented by the instance.
 *
 * @param baseUri The base Uri.
 * @return The {@link Uri} represented by the instance.
 */
public Uri resolveUri(String baseUri) {
  return UriUtil.resolveToUri(baseUri, referenceUri);
}
 
Example 20
Source File: RangedUri.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the resolved {@link Uri} represented by the instance.
 *
 * @param baseUri The base Uri.
 * @return The {@link Uri} represented by the instance.
 */
public Uri resolveUri(String baseUri) {
  return UriUtil.resolveToUri(baseUri, referenceUri);
}