From eb5cbd902b5090f544c111bd590a1a2d7b9dde26 Mon Sep 17 00:00:00 2001 From: hhouillon Date: Thu, 10 Aug 2023 13:43:00 +0200 Subject: [PATCH] DASH UrlTemplate parses template if it contains more than one time each identifier --- .../exoplayer/dash/manifest/UrlTemplate.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/UrlTemplate.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/UrlTemplate.java index 8d36fce52c..58cd3e594c 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/UrlTemplate.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/UrlTemplate.java @@ -51,11 +51,16 @@ public final class UrlTemplate { * @throws IllegalArgumentException If the template string is malformed. */ public static UrlTemplate compile(String template) { - // These arrays are sizes assuming each of the four possible identifiers will be present at - // most once in the template, which seems like a reasonable assumption. - String[] urlPieces = new String[5]; - int[] identifiers = new int[4]; - String[] identifierFormatTags = new String[4]; + // We can have more than once each identifier in the template so we need + // to count the total number of identifiers present in the template + int identifiersCount = 0; + String[] identifiersNames = { REPRESENTATION, NUMBER, BANDWIDTH, TIME }; + for(String identifierName : identifiersNames){ + identifiersCount += template.split("\\$" + identifierName + "\\$").length - 1; + } + String[] urlPieces = new String[identifiersCount+1]; + int[] identifiers = new int[identifiersCount]; + String[] identifierFormatTags = new String[identifiersCount]; int identifierCount = parseTemplate(template, urlPieces, identifiers, identifierFormatTags); return new UrlTemplate(urlPieces, identifiers, identifierFormatTags, identifierCount); }