parseSubtitle static method

PipFlutterPlayerAsmsSubtitle parseSubtitle(
  1. String masterPlaylistUrl,
  2. XmlElement node
)

Implementation

static PipFlutterPlayerAsmsSubtitle parseSubtitle(
    String masterPlaylistUrl, XmlElement node) {
  final String segmentAlignmentStr =
      node.getAttribute('segmentAlignment') ?? '';
  String? name = node.getAttribute('label');
  final String? language = node.getAttribute('lang');
  final String? mimeType = node.getAttribute('mimeType');
  String? url =
      node.getElement('Representation')?.getElement('BaseURL')?.text;
  if (url?.contains("http") == false) {
    final Uri masterPlaylistUri = Uri.parse(masterPlaylistUrl);
    final pathSegments = <String>[...masterPlaylistUri.pathSegments];
    pathSegments[pathSegments.length - 1] = url!;
    url = Uri(
            scheme: masterPlaylistUri.scheme,
            host: masterPlaylistUri.host,
            port: masterPlaylistUri.port,
            pathSegments: pathSegments)
        .toString();
  }

  if (url != null && url.startsWith('//')) {
    url = 'https:$url';
  }

  name ??= language;

  return PipFlutterPlayerAsmsSubtitle(
      name: name,
      language: language,
      mimeType: mimeType,
      segmentAlignment: segmentAlignmentStr.toLowerCase() == 'true',
      url: url,
      realUrls: [url ?? '']);
}