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:
cordova.plugins.spotifyAuth.authorize(config)
.then(({ accessToken, expiresAt }) => {
this.result = { access_token: accessToken, expires_in: expiresAt};
this.presentAlert(accessToken);
SpotifySDK.connectToAppRemote();
SpotifySDK.login();
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.