Describe the bug
After tapping play (which will play an audio file via audio_service) swipe down from the left top-corner to see the notification screen on iOS Simulator. I expect to see the iOS audio player there, but it doesn't appear. It will take sometime for it to appear, sometimes you have to trigger pause/stop states. I am calling AudioServiceBackground.setState(...) onStart, onPlay and so on.
Another thing is that most of the times when player appears, it seems to be out-of-sync with audio_service. Say I want to show "pause" button when audio is playing and "play" button when audio is paused. In most cases Simulator will just show "play" button (even if it's completely commented out in my code).
That being said, I can see that MediaItems are updating correctly and swiftly.
Running the same application on Android Emulator, I can see that all the states and buttons are updated correctly and in time, and "audio-player notification" appears immediately.
Minimal reproduction project
I haven't tested this on a real device, but I tried this both on the application that I'm building and on the example project for audio_service.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
An audio player should appear in the notification center as soon as I open it, given that the setState was called before that and audio is playing
Screenshots
Video demo
Runtime Environment (please complete the following information if relevant):
_Simulator_
Version 11.4.1 (921.9)
SimulatorKit 581.9.1
CoreSimulator 704.12.1
_Simulator iOs version_
ios 13.4
Flutter SDK version
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en-SE)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.44.2)
[✓] Connected device (1 available)
• No issues found!
Additional context
I'm using audio_service with just_audio.
Is it just Simulator implementation of the notification center or something else?
Have anyone else experienced that? Will it work faster on real device?
Hi @Drabuna , to help me to investigate this bug more easily, would you be able to fill in the bug report template? Make sure all fields are supplied where applicable, and in particular the minimal reproduction project (if not the example project).
@ryanheise Sorry, wasn't sure if it should be considered a bug. I've now edited the initial question to cover the template.
Thanks for the report, @Drabuna . I have a somewhat limited testing environment (simulator via MacInCloud) which lets me test up to iOS 13.3, and like you I don't have a physical device. Perhaps someone else would be able to confirm the delay you observed.
I did however try the iOS 13.3 simulator and tried pulling down from the top left corner. I didn't notice any difference pulling down from there and the top centre, or top right, in all cases I saw an empty notifications area.
What simulated iPhone model did you test with?
I've tested with simulated iPhone 11, 11 pro and max.
I've also implemented a simple project in Swift that just plays audio and shows player in the notification center. Player shows up really fast, so it's not an iOS Simulator problem. Will keep looking, maybe something in how audio_service is setup.
I've discovered a workaround - not sure why this works the way it does, but anyway.
I've noticed that when an audio task isolate is killed, the next isolate will show the player in the notification center.
So, just create:
void _iosNotificationCenterInitTaskEntrypoint() async {
AudioServiceBackground.run(() => IosNotificationCenterInitTask());
}
class IosNotificationCenterInitTask extends BackgroundAudioTask {
@override
Future<void> onStart() async {
await AudioServiceBackground.setState(
controls: [],
basicState: BasicPlaybackState.playing,
);
}
@override
Future<void> onStop() async {}
}
Note that if basicState is set to something else than BasicPlaybackState.playing it will not work. You can call AudioServiceBackground.setState right after, to set it to stopped.
Also note that trying to call same setState from your BackgroundAudioTask will not work.
And invoke it somewhere in the app below AudioServiceWidget and before playing anything, the earlier the better
AudioService.start(backgroundTaskEntrypoint: _iosNotificationCenterInitTaskEntrypoint);
After this is done, you should be able to start your normal audio isolate task, and it will work as it should, and the notification center will display the player immediately.
This doesn't fix the buttons being out of sync with the app state though.
@ryanheise Grab the modified example here if you want to try it out main.dart.txt
That is very interesting. I'd like to understand what's going on here, but sadly I have been unable to reproduce it. When I get a chance, I'll try simulating an iPhone 11.
I got to test it out on a real device, and none of the issues I mentioned are present.
So, on a real device (iPhone X + ios 13.4.1) - the player in the notification center appears as soon as you start playing. Buttons are also in sync - works great.
So I guess it's some sort of an issue with the simulator, but not critical as long as it works properly on a real device.