com.google.android.exoplayer2.util.UriUtil Java Examples

The following examples show how to use com.google.android.exoplayer2.util.UriUtil. 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 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 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 #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 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 #6
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 #7
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 #8
Source File: HlsChunkSource.java    From Telegram 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 #9
Source File: HlsChunkSource.java    From Telegram 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 #10
Source File: SsManifest.java    From Telegram-FOSS 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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.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 #19
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 #20
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 #21
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 #22
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 #23
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected static String parseBaseUrl(XmlPullParser xpp, String parentBaseUrl)
    throws XmlPullParserException, IOException {
  xpp.next();
  return UriUtil.resolve(parentBaseUrl, xpp.getText());
}
 
Example #24
Source File: HlsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static void addResolvedUris(String baseUri, List<HlsUrl> urls, List<Uri> out) {
  for (int i = 0; i < urls.size(); i++) {
    out.add(UriUtil.resolveToUri(baseUri, urls.get(i).url));
  }
}
 
Example #25
Source File: HlsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static void addResolvedUris(String baseUri, List<HlsUrl> urls, List<Uri> out) {
  for (int i = 0; i < urls.size(); i++) {
    out.add(UriUtil.resolveToUri(baseUri, urls.get(i).url));
  }
}
 
Example #26
Source File: DashManifestParser.java    From K-Sonic with MIT License 4 votes vote down vote up
protected static String parseBaseUrl(XmlPullParser xpp, String parentBaseUrl)
    throws XmlPullParserException, IOException {
  xpp.next();
  return UriUtil.resolve(parentBaseUrl, xpp.getText());
}
 
Example #27
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected static String parseBaseUrl(XmlPullParser xpp, String parentBaseUrl)
    throws XmlPullParserException, IOException {
  xpp.next();
  return UriUtil.resolve(parentBaseUrl, xpp.getText());
}
 
Example #28
Source File: RangedUri.java    From K-Sonic with MIT License 2 votes vote down vote up
/**
 * Returns the resolved uri represented by the instance as a string.
 *
 * @param baseUri The base Uri.
 * @return The uri represented by the instance.
 */
public String resolveUriString(String baseUri) {
  return UriUtil.resolve(baseUri, referenceUri);
}
 
Example #29
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 #30
Source File: RangedUri.java    From K-Sonic with MIT License 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);
}