didChangeAppLifecycleState method

  1. @override
void didChangeAppLifecycleState(
  1. AppLifecycleState state
)
override

Handler for AppLifecycleState changes.

This function handles the automatic pause and resume when the app lifecycle state changes. There is NO NEED to call this function directly directly.

Implementation

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
  if (state == AppLifecycleState.resumed) {
    if (isPlaying && audioPlayer.state == PlayerState.paused) {
      audioPlayer.resume();
    }
  } else {
    audioPlayer.pause();
  }
}