react-native-spotify-remote: The operation couldn’t be completed. Connection refused
Below is my code. I got accessToken but when I call SpotifyRemote.connect(session.accessToken), I got this error
Possible Unhandled Promise Rejection (id: 2): Error: Connection attempt failed. Stream error. The operation couldn’t be completed. Connection refused
SpotifyAuth.getSession().then((session) => {
if (session != undefined && session.accessToken != undefined) {
SpotifyRemote
.connect(session.accessToken)
.then(() => {
SpotifyRemote.playUri(`spotify:track:${songId}`);
})
.catch(this.onError);
} else {
console.log("session failed.=============")
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 19 (7 by maintainers)
@yingtao-futurewonder glad that was able to help. Did you see in the docs I sent you that if you pass in
playUri: ""it will attempt to play from the last position / song? That might be less jarring for your application. As for the second piece. iOS is pretty aggressive with how it backgrounds applications which makes the connection to spotify somewhat challenging to maintain. For the time being, in my app I’ve been checking to see if a connection has been lost and if it has, re-running the auth->playUri flow to make sure that spotify is started and not backgrounded.Hope that helps.
Has anyone been able to connect back to the iOS Spotify client (after it becomes inactive) without switching back to Spotify app again? I thought I’d just cache the token and connect to Spotify client if somehow we get disconnected but it seems like we’d have to open the Spotify app each time.
@cjam Thank you
@cjam Thank you so much! it does help!