Why can't I use the Spotify SDK in capacitor?

I am using Ionic with Capacitor to build an app, which interacts with the Spotify APi.
Therefore I use the cordova-spotify-auth plugin and the capacitor-spotify plugin.

In the app, you are supposed to log in to Spotify and then the app is supposed to play a song on the device via the native Spotify mobile app.
The login via the cordova-spotify-auth plugin works, I also get an access token. However, using the Spotify SDK via capacitor-spotify plugin does not work. I get the following error messages:

2021-04-25 00:07:25.518 2445-2445/io.ionic.starter
E/Capacitor/Console: File: http://localhost/home-home-module.js - Line
1668 - Msg: Spotify SDK isn’t supported on the web

2021-04-25 00:07:25.526 2445-2445/io.ionic.starter E/Capacitor/Console: File:
http://localhost/vendor.js - Line 59199 - Msg: ERROR Error: Uncaught
(in promise): Spotify SDK isn’t supported on the web

This is my code:

.then(({ accessToken, expiresAt }) => {
      this.result = { access_token: accessToken, expires_in: expiresAt};
      SpotifySDK.play({uri: 'spotify:track:4q6dqyGM25sKFU8nYAGRe4'});

Wouldn’t Capacitor have to translate the code into native languages and thus make the Spotify SDK work?

Also, if you know any other way to play a song in the native Spotify mobile app via Capacitor or Cordova, please let me know.

How are you running the app? Locally via ionic serve or on a mobile device/simulator? Given the error message:

“Spotify SDK isn’t supported on the web”

I’m guessing on the web. cordova-spotify-auth is a Cordova plugin, which traditionally does not offer web support - only iOS and Android.

Same issue with the capacitor-spotify plugin. Capacitor plugins are more web-friendly so can have web and mobile implementations. However, looking at this specific plugin, the web implementation code here, it’s not implemented.

Try testing on a device or simulator. If you need web support, you can petition the plugin author to add support by opening a GitHub issue on the repo.


Dear netkow,
I tried it on Android Studio on a simulator, unfortunately it doesn’t work. It also does not work on my Android device connected via USB debugging. I get the same error:
“Line 1618 - Msg: Spotify SDK isn’t supported on the web”