react-native-spotify-remote
react-native-spotify-remote copied to clipboard
Authorize Succeeds then connect fails with: Connection attempt failed. Ensure the Spotify app is installed, and try to reconnect. Stream error. Reconnect the transport to the Spotify app. The operation couldn’t be completed. Connection refused
Hello @cjam,
Thank you kindly for the great library.
I'm having some trouble at the moment and cannot for the life of me find a solution to our this issue. A lot of our testers are reporting that their Spotify authorisation succeeds and then the connection to Spotify fails with this error: Connection attempt failed. Ensure the Spotify app is installed, and try to reconnect. Stream error. Reconnect the transport to the Spotify app. The operation couldn’t be completed. Connection refused.
I'm not able to reliably replicate this error, our logs tell us that approx 50% of our testers are experiencing this issue. Sometimes a user is able to retry the auth flow and it succeeds immediately, and sometimes it will only succeed the next day.
Because nobody has raised this issue, it's possible that it's my code that's causing this error. My connect to Spotify method where this error is thrown looks like this:
export const connectToSpotify = async () => {
const isConnected = await SpotifyRemote.isConnectedAsync();
if (isConnected) {
return;
}
const spotifyConfig: ApiConfig = {
clientID: '<clientID>',
redirectURL: '<redirectURL>',
tokenRefreshURL: `<api_base_url>/api/spotify/refresh`,
tokenSwapURL: `<api_base_url>/api/spotify/swap`,
scopes: [
ApiScope.AppRemoteControlScope,
ApiScope.UserFollowReadScope,
ApiScope.PlaylistReadPrivateScope,
ApiScope.UserReadPlaybackStateScope,
ApiScope.UserReadPrivateScope,
ApiScope.UserReadEmailScope,
],
showDialog: false,
playURI: '',
};
const existingSession = await SpotifyAuth.getSession();
if (existingSession && existingSession.accessToken) {
try {
await SpotifyRemote.connect(existingSession.accessToken);
} catch (e) {
// Reauth if connection has been dropped
await SpotifyRemote.disconnect();
await SpotifyAuth.endSession();
const freshSession = await SpotifyAuth.authorize(spotifyConfig);
await SpotifyRemote.connect(freshSession.accessToken);
}
} else {
// No existing session was found so connect for the first time
const firstTimeSession = await SpotifyAuth.authorize(spotifyConfig);
// The line below throws the error
await SpotifyRemote.connect(firstTimeSession.accessToken);
}
};
We are also using the latest version of this library. In all test cases the users had Spotify installed on their devices and approved the requested scoped.
Hey @P-Russell .
I have encountered this issue before when spotify was already running but not playing music. All of your config and code looks good, and by the looks of it it should cause Spotify to start playing whatever it was playing previously.
Can you tell your testers to close spotify and then try to run your app again? (I'm not saying this is a good long term solution, but it might help narrow down the problem.)
Hi @cjam .
Thanks for reading my code. It's nice to know I've not gone insane yet.
So it turns out that restarting / closing spotify does improve the chances of connecting. Is there a solution to handle this gracefully?
@cjam @P-Russell We are also facing the same issue. Were you able to find a solution?
Sorry the delay on this one. I haven't been able to find a good solution to this one. It seems like it's something on the Spotify side. But I haven't had time to investigate other possibilities
Same problem on Android device. Authorize Succeeds but when i try to connect, i have such kind of Error: Spotify connection failed: could not find the Spotify app, it may need to be installed. p.s. On IOS work's fine...
Same error "Spotify connection failed: could not find the Spotify app, it may need to be installed." Spotify app is installed, auth success but after I get error. Device: xiaomi MI 9 t pro.
iOS is ok.
Hmm seems like it may be the same issue as #166 . What version of this library are you using?
Hmm seems like it may be the same issue as #166 . What version of this library are you using?
@cjam thx for your fast reply!
Maybe, but in my situation i pass auth and get session obj. but then drops error when i try to remote connect. I used 0.3.10 version of library, and then fide out to update it to 0.3.11-1 and try again. But after installing it my app stops to compile and throws 82 errors something like this

If it is on Android, this is due to the new limitation by Android 11: https://github.com/cjam/react-native-spotify-remote/issues/161, causing the sdk to not detect the Spotify App, resulting in "Spotify connection failed: could not find the Spotify app, it may need to be installed."
If it is on Android, this is due to the new limitation by Android 11: #161, causing the sdk to not detect the Spotify App, resulting in "Spotify connection failed: could not find the Spotify app, it may need to be installed."
yeap that`s android 11, so how to fix this trouble...? i install 0.3.11-1 version of library but i got more errors which brake my app...
If it is on Android, this is due to the new limitation by Android 11: #161, causing the sdk to not detect the Spotify App, resulting in "Spotify connection failed: could not find the Spotify app, it may need to be installed."
yeap that`s android 11, so how to fix this trouble...? i install 0.3.11-1 version of library but i got more errors which brake my app...
You can try my fork in the meantime https://www.npmjs.com/package/@hoangvvo/react-native-spotify-remote. There seem to be an issue in git module. I addressed this in https://github.com/cjam/react-native-spotify-remote/pull/162#issuecomment-959092496. So it might work when @cjam released a new version that included the latest PR.
You can try my fork in the meantime https://www.npmjs.com/package/@hoangvvo/react-native-spotify-remote. There seem to be an issue in git module. I addressed this in #162 (comment). So it might work when @cjam released a new version that included the latest PR.
Ok, thx a lot! should be waiting for release...
@hoangvvo @Iksysia the previous pre-release was broken, not sure why it didn't have the submodules. Anyways, have released a new pre-release version 0.3.11-2 you can install it using @next
Let me know if it works.