Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

android: foreground -> background -> switch next song -> foreground will be played again

Open zhushenwudi opened this issue 3 years ago • 1 comments

Flutter Version

My version : 2.10.4

Lib Version

My version : 3.0.4+1

Platform (Android / iOS / web) + version

Platform : android

Describe the bug

Switch to the background when a song is playing, switch to the next song, return to the foreground, and the song will be played again

zhushenwudi avatar Apr 27 '22 13:04 zhushenwudi

This is not a bug, it is only an issue by business, if repository owner read my issue, consider whether to add to these code.

I add these code in "assets_audio_player.dart" about 310 lines.

final BehaviorSubject<bool> _isFirstBackgroundToForeground = BehaviorSubject<bool>.seeded(false);
bool get isFirstBackgroundToForeground {
  final isFirst = _isFirstBackgroundToForeground.stream.value;
  _isFirstBackgroundToForeground.value = false;
  return isFirst;
}

And then I add these code at AppLifecycleObserver callback in "assets_audio_player.dart".

onChanged: (isActive) {
  _isFirstBackgroundToForeground.value = isActive;
}

At last, can use at main code, it can not broken player logic because you can not set value.

mPlayer.isFirstBackgroundToForeground

zhushenwudi avatar May 03 '22 03:05 zhushenwudi