ryanheise / just_audio

Audio Player
1.03k stars 651 forks source link

If the number of children of ConcatenatingAudioSource is too large, there will be performance problems #539

Closed itning closed 2 years ago

itning commented 2 years ago

Which API doesn't behave as documented, and how does it misbehave? If set setShuffleModeEnabled = true and ConcatenatingAudioSource has about 1300 children The player will become very lagging.

Minimal reproduction project

Future<void> setSource(List<MusicDataContent> musics, int initIndex) async {
    ConcatenatingAudioSource concatenatingAudioSource =
    ConcatenatingAudioSource(children: []);
    List<AudioSource> children = [];
    for (var music in musics) {
      String musicUrl = HttpHelper.get().getMusicUrl(music.musicId!);
      Uri coverUri = Uri.parse(HttpHelper.get().getCoverUrl(music.musicId!));
      MediaItem mediaItem = MediaItem(
        id: music.musicId!,
        artist: music.singer ?? '',
        title: music.name ?? '',
        artUri: coverUri,
      );
      AudioSource audioSource;
      audioSource = AudioSource.uri(
        Uri.parse(musicUrl),
        tag: mediaItem,
      );
      children.add(audioSource);
    }
    concatenatingAudioSource.addAll(children);
    try {
      _player.setAudioSource(concatenatingAudioSource,
          initialIndex: initIndex);
    }  catch (e) {
      LogHelper.get().error('catch exception', e);
    }
  }

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. _player.setShuffleModeEnabled(true);
  2. _player.seekToNext()

Error messages

No error message

Expected behavior No lagging behavior

Screenshots

image

The code in the red circle in the figure below takes up a lot of CPU time :

image

Smartphone (please complete the following information):

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.2, on Microsoft Windows [Version 10.0.19043.1266], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] IntelliJ IDEA Ultimate Edition (version 2021.2)
[√] Connected device (3 available)

• No issues found!

Additional context

Nothing

ryanheise commented 2 years ago

Closing (for similar reasons as before). @itning are you not reading my previous replies to you? I would appreciate valid bug reports, but when you keep posting invalid ones without reading the instructions carefully it actually creates more of a burden for me and does not help.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.