Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
867 stars 567 forks source link

[HELP]: Android Background Playback Error #600

Open xaestrus opened 3 years ago

xaestrus commented 3 years ago

I tried implementing the background playback on Android. Here I built the simplest recreation of the issue:

Future<void> _play() async {
    for(int i=0;i<100;i++){
      tracks.add(Track(
      trackPath: 'https://www.canardoux.xyz/tau_sound/web_example/assets/extract/05.mp3',
      codec: Codec.mp3,
      trackTitle: 'This is a record',
      trackAuthor: 'from flutter_sound',
      ));
    }
    await _mPlayer.openAudioSession(
        withUI: true);
    await play();
  }

  static var tracks = [];
  static int counter = 0;

  Future play() async {
    await _mPlayer.startPlayerFromTrack(
        tracks[counter],
        defaultPauseResume: false,
        removeUIWhenStopped: true,
        whenFinished: () async {
          print('here $counter !');
          counter++;
          print('x');
          if(counter<100) {
            await play();
          }
        });
  }

Basically, I want to send a track/list of tracks to be played with media controls, and after player finishes playing I want it to fetch new list of tracks and play them. Unfortunately, on Android it causes problems if I lock my phone. After a few minutes of playback it gives me a E/MediaPlayerNative( 9930): error (-38, 0) , the media controls disappear, and player stops playing. However, what's interesting is that it comes back to normal if I reopen the app.

I am not sure if it's an error on my part or it is a bug because I might have missed some way of adding tracks to the queue efficiently, so I put it as HELP.

Larpoux commented 3 years ago

Hi @xaestrus ,

Your request overlaps #525.

525 is already planned. I put a link to your issue inside #525 and close this issue.

(managing duplicates is not easy)

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.