session.interruptionEventStream.listen is not triggering in ios
void _initAudioSession() async { final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration.music());
await session.setActive(true);
session.interruptionEventStream.listen((event) {
if (event.begin) {
betterPlayerController.pause();
} else {
// betterPlayerController.play();
}
});
}
Has a solution for this issue been provided yet? I am experiencing the same problem.
I'm not going to be of much help with diagnosing specific situations, since all this plugin does is wrap around the native iOS API. If setActive is returning false, that might tell you whether you can expect following interruptions to happen or not. The music preset is defined as category=playback, mode=default:
https://pub.dev/documentation/audio_session/latest/audio_session/AudioSessionConfiguration/AudioSessionConfiguration.music.html
So this is equivalent to the iOS native call:
AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
AVAudioSession.sharedInstance().setActive(true)
If you like, you can try interacting more directly with the iOS-specific API by directly using the AVAudioSession API exposed by this plugin rather than the platform-neutral AudioSession API. Then you can try to experiment with the behaviour of the iOS API. Note that AudioSession provides interruptionEventStream while AVAudioSession provides interruptionNotificationStream with the iOS specific notification properties. This basically listens to the AVAudioSessionInterruptionNotification on the native side. Note that interruptions are not notified to your app in as many situations on iOS as they are on Android, that's just the behaviour of the OS.
It might be more fruitful to ask this type of question on StackOverflow as a native iOS code question rather than a Flutter question once you understand the iOS specific API, and you'll likely find more people who can help you with the specific behaviour of the iOS API which is being wrapped here.