ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
797 stars 479 forks source link

PlaybackState Stream and Position Stream always null in Safari #688

Open andy-t-wang opened 3 years ago

andy-t-wang commented 3 years ago

Which API doesn't behave as documented, and how does it misbehave? AudioService.positionStream and AudioService.playbackStateStream.distinct(), both streams are null on Safari

Minimal reproduction project Using the example code I hosted it and when on safari the seekbar doesn't move and play button doesn't switch to pause because the two streams are always returning null. https://andy-t-wang.github.io/audioservice/#/ Using the Null Safety version

To Reproduce (i.e. user steps, not code) Visit https://andy-t-wang.github.io/audioservice/#/ where I hosted the web version of the example code

Error messages

Not seeing any error messages this is working fine on chrome.

Expected behavior Streams expected to return playing state and position accurately

Screenshots If applicable, add screenshots to help explain your problem.

Runtime Environment (please complete the following information if relevant):

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.5, on macOS 11.2.3 20D91 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.55.2)
[✓] Connected device (1 available)

• No issues found!

Additional context Add any other context about the problem here.

ryanheise commented 3 years ago

Can you confirm that this is the unmodified official example? Does the bug also occur on the one-isolate branch?

andy-t-wang commented 3 years ago

Yeah its unmodified, I just cloned the audio_service repo built it for web and deployed it.

ryanheise commented 3 years ago

According to @keaganhilliard in #457 there are some known issues with Safari, so for the moment this would not work for you currently. That being said, if you need a solution urgently, you can try #632 based on the one-isolate branch, and then make your own local change to force it to use NoOpAudioService for the web. This would completely disable the media session code but should allow everything else to work.

ryanheise commented 3 years ago

I have merged #632 so one thing you may try is overriding the platform manually to the new noop platform.

andy-t-wang commented 3 years ago

How would I override this? Would I need to fork the repo and make the change?

keaganhilliard commented 3 years ago

You would need to include the AudioServicePlatformInterface in your pubspec like so:

audio_service_platform_interface: 
    git:
      url: https://github.com/ryanheise/audio_service.git
      ref: one-isolate
      path: audio_service_platform_interface

And then at some point after you have detected that you are running in Safari. Set the instance like this:

AudioServicePlatform.instance = NoOpAudioService();
keaganhilliard commented 3 years ago

The issue is that Safari just flat out doesn't support the MediaSession APIs so there is probably an exception that is not being caught at some point (web debugging is still pretty painful even with Chrome). It would take some digging and unfortunately my Mac is no longer usable, so I can't really debug it myself.

andy-t-wang commented 3 years ago

Ok sounds good will take a look, also I think from memory the play button used to work in the version before null safety. The seekbar did not and just crashed.

andy-t-wang commented 3 years ago

You would need to include the AudioServicePlatformInterface in your pubspec like so:

audio_service_platform_interface: 
    git:
      url: https://github.com/ryanheise/audio_service.git
      ref: one-isolate
      path: audio_service_platform_interface

And then at some point after you have detected that you are running in Safari. Set the instance like this:

AudioServicePlatform.instance = NoOpAudioService();

Do I need to be using the one-isolate branch for my main audio service? I'm currently on null safety

keaganhilliard commented 3 years ago

Yeah all of this development has been focused on one-isolate. The NoOpAudioService only exists in that branch.