Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS simulator - player on lock screen/notifications slow to appear #301

Closed
Drabuna opened this issue May 4, 2020 · 8 comments
Closed

iOS simulator - player on lock screen/notifications slow to appear #301

Drabuna opened this issue May 4, 2020 · 8 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@Drabuna
Copy link

Drabuna commented May 4, 2020

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:

  1. Start the example project (from 0.8.0 release) on iOs Simulator
  2. Tap on "Audio Player"
  3. It will start playing automatically, otherwise hit "Play" button.
  4. Swipe from top-left corner, to see the notification center.
  5. See that "audio player" is not there.

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?

@Drabuna Drabuna added 1 backlog bug Something isn't working labels May 4, 2020
@ryanheise
Copy link
Owner

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).

@Drabuna
Copy link
Author

Drabuna commented May 5, 2020

@ryanheise Sorry, wasn't sure if it should be considered a bug. I've now edited the initial question to cover the template.

@Drabuna Drabuna changed the title Question: iOS simulator - player on lock screen/notifications slow to appear iOS simulator - player on lock screen/notifications slow to appear May 5, 2020
@ryanheise
Copy link
Owner

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?

@Drabuna
Copy link
Author

Drabuna commented May 5, 2020

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.

@Drabuna
Copy link
Author

Drabuna commented May 5, 2020

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

@ryanheise
Copy link
Owner

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.

@Drabuna
Copy link
Author

Drabuna commented May 7, 2020

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.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants