audio_service
audio_service copied to clipboard
iOS notifications only displayed after second audio played
Describe the bug
The example app does not reliably display "now playing" notifications. They don't show up the first time audio plays. If you exit the player and then play again, the notifications are displayed.
I'm happy to debug more to see if I can find a fix, but some pointers would be helpful. I've verified that MPNowPlayingInfoCenter.defaultCenter.nowPlayingInfo is being initialized, and it looks identical to me on both the first and second play. Let me know if you have ideas for things to check for additional debugging.
Minimal reproduction project
Example app reproduces the problem.
To Reproduce Steps to reproduce the behavior: Reproduction steps:
- install the example app on a simulator (I'm using iPhone SE simulator)
- click "audio player" (audio starts playing)
- check for notifications: none. this is a bug.
- click the stop button
- click 'audio player' again
- check for notifications: this time they are visible.
Error messages
No error messages I can see.
Expected behavior
Notifications should appear the first time audio plays.
Screenshots
n/a
Runtime Environment (please complete the following information if relevant):
- Device: iPhone SE second generation (simulator)
- OS: iOS 13.5
Flutter SDK version
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.5 19F96, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 3.6)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.3.5)
[✓] IntelliJ IDEA Community Edition (version 2017.2.2)
[✓] Connected device (1 available)
Additional context Add any other context about the problem here.
Thanks for offering to investigate and debug this one.
I think a workaround for this was posted here some time ago but searching through the past issues I was unable to find it. From memory, the workaround had something to do with preemptively creating and destroying a flutter isolate, which suggests somehow this may relate to the flutter_isolate
package.
I only have access to an iOS simulator and I haven't been able to reproduce it unfortunately, but hopefully the above information provides some hints.
This one reproduces just fine in a simulator, thankfully.
Creating and destroying an isolate had no impact.
Starting and stopping the audio does fix it.
So I guess that narrows it down a little bit. I can play around to find the minimal steps necessary to make the problem go away, and that should help find what's going wrong.
Ah, I just found the issue I was referring to earlier:
https://github.com/ryanheise/audio_service/issues/301#issuecomment-624152228
The suggested workaround is quite interesting, particularly that it only works if the first task calls setState
to playing
. I have changed the state model since then, but I think the effect playing
has on the iOS plugin should be logically equivalent, so I would guess this fact still holds in the latest code. In any case, this could be an important hint as to what's going on. It might be a timing or sequencing issue.
Interestingly, Drabuna also noted that this only happens on the simulator and not on a real device, and also that on the simulator the notification eventually appears, just after a delay.
I've seen this as well, but can confirm that it's only affected my simulator and the issue was gone when actually built and deployed to iOS device.
There are two separate issues going on:
iPhone 7 and below: notifications don't work at all. Tested in simulator for iPhone 5-7, and on iPhone 5s real device. Not sure if this is WAI or not. I thought notifications were supported even on these older devices?
iPhone 8 and up: notifications only appear after the second run, so possibly related to issue #301. I've only tested a simulator here, no idea whether this happens on a real device.
Is there an example objective C app that gets this right? The examples I'm seeing on Apple's web site are Swift, makes it a bit hard to judge whether the objective C APIs are being used correctly.
Is this still an issue with 0.18.0?