brim-borium / spotify_sdk

Flutter Package to connect the spotify sdk
https://pub.dev/packages/spotify_sdk
Apache License 2.0
153 stars 82 forks source link

web sdk: ignore browser autoplay error #145

Closed nzoschke closed 3 years ago

nzoschke commented 3 years ago

Recently the Spotify Web Playback SDK added support for Safari both on iOS and desktop, however these browsers have extra media activation policies that trigger an authentication_error when starting playback.

Before this change, this browser authentication_error error went down the SDK disconnect path making it impossible to recover.

With this change the error is suppressed, allowing us to present a user with a button to call resume() and start playback as normal.

nzoschke commented 3 years ago

The error string approach feels fragile, but I don't see a better way. Here's one of the full error events I observed:

{message: "Authentication Error: Browser prevented autoplay due to lack of interaction", name: "", level: 0}
nzoschke commented 3 years ago

I'm doing a bit more investigation if handling this error is truly necessary.

In my app at least, playback doesn't start without user interaction. So perhaps I can automatically transfer paused playback first, then explicitly start playback with the user interaction.

nzoschke commented 3 years ago

More research shows that handling this error is necessary. Transferring to the web SDK device doesn't seem to be working outside of playing a track with the SDK. The first play triggers the browser error, a second explicit button press gets the SDK going.

fotiDim commented 3 years ago

@nzoschke thanks for the fix! Shall we also add an entry in the Readme?

nzoschke commented 3 years ago

@fotiDim updated the readme, let me know how it sounds.

I also added something to the readme which fixes #100. I could split that out into its own thing if necessary.