uri static method

UriAudioSource uri(
  1. Uri uri,
  2. {Map<String, String>? headers,
  3. dynamic tag}
)

Creates an AudioSource from a Uri with optional headers by attempting to guess the type of stream. On iOS, this uses Apple's SDK to automatically detect the stream type. On Android, the type of stream will be guessed from the extension.

If you are loading DASH or HLS streams that do not have standard "mpd" or "m3u8" extensions in their URIs, this method will fail to detect the stream type on Android. If you know in advance what type of audio stream it is, you should instantiate DashAudioSource or HlsAudioSource directly.

If headers are set, just_audio will create a cleartext local HTTP proxy on your device to forward HTTP requests with headers included.

Implementation

static UriAudioSource uri(Uri uri,
    {Map<String, String>? headers, dynamic tag}) {
  bool hasExtension(Uri uri, String extension) =>
      uri.path.toLowerCase().endsWith('.$extension') ||
      uri.fragment.toLowerCase().endsWith('.$extension');
  if (hasExtension(uri, 'mpd')) {
    return DashAudioSource(uri, headers: headers, tag: tag);
  } else if (hasExtension(uri, 'm3u8')) {
    return HlsAudioSource(uri, headers: headers, tag: tag);
  } else {
    return ProgressiveAudioSource(uri, headers: headers, tag: tag);
  }
}