Why does just_audio_background slow down loading an audio source on Android?

38 Views Asked by At

I'm using just_audio in Flutter to play HLS streams like the following: https://d22tbkdovk5ea2.cloudfront.net/audio/projects/62/podcasts/9395179/media/2d0275a5c81574e766a2d57317664a7c.m3u8

This has been working with no issues.

I recently added the just_audio_background plugin, and on Android this seems to cause the loading of the FIRST audio stream to slow down dramatically (anything up to 20 seconds). iOS appears to be unaffected, and subsequent (after the first load) loads are also fast on Android.

Any ideas as to what causes this and what can be done to work around?

My setup is fairly simple:

I have a singleton player instance:

player = AudioPlayer(
    audioLoadConfiguration: AudioLoadConfiguration(
      androidLoadControl: AndroidLoadControl(
        prioritizeTimeOverSizeThresholds: true,
      ),
    ),
);

Configure background plugin in main()

JustAudioBackground.init(
    androidNotificationChannelId: 'za.co.dailymaverick.app.channel.audio',
    androidNotificationChannelName: 'Audio playback',
);

Fetch data and play:

    await Audio.player.setAudioSource(
    HlsAudioSource(
          Uri.parse(url),
          tag: MediaItem(
              id: id,
              title: title,
              album: "Album",
              artUri: Uri.parse(
                imageUrl,
              )),
        ),
     );

This all works fine, but the very first setAudioSource takes very to complete. If I remove the background init code, it's very fast.

0

There are 0 best solutions below