Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpotifyAppRemote.connect gets stuck indeterminately, 0.8.0, 0.7.2, multiple Android devices and OS #348

Open
Fot1s opened this issue Aug 8, 2023 · 1 comment

Comments

@Fot1s
Copy link

Fot1s commented Aug 8, 2023

*Hi, we are trying to use Spotify App Remote library to control spotify via voice control inside our application.
Our issue is that from time to time, SpotifyAppRemote.connect fails to connect or report an exception.
It seems that Spotify's service gets in a 'stuck' state where it cannot respond back to client apps.
When this happens, trying to drop / reconnect does not resolve the issue, but a new connection seem to happen,
which is then immediately problematic (same stuck state).
After some indeterminate time that varies from some seconds to several minutes, the situation seems to fix it self, and at that point a number of disconnection and timeout exceptions are reported one after the other for the previously made connection attempts.

Bringing Spotify in the foreground, restarting the app, or killing the background service does not seem to help.

This makes the sdk unusable for us, could you investigate?
Some code attached bellow:

Issue found on 07.JUL.23.

SDK Version: 0.8.0, 0.7.2

OS Version: 11, 12, 13

Code Sample:

We initially (once / on app install) use the following code to get app-remote-control and authorise our app

    val builder = AuthorizationRequest.Builder(CLIENT_ID, AuthorizationResponse.Type.CODE, REDIRECT_URI)

    builder.setScopes(
        arrayOf(
            "streaming",
            "app-remote-control",
            "user-read-email",
            "user-read-private",
            "user-read-playback-state",
            "user-modify-playback-state",
            "user-top-read",
            "user-follow-modify",
            "user-library-modify",
            "user-read-currently-playing",
            "user-read-recently-played"
        )
    )
    val request = builder.build()

    AuthorizationClient.openLoginActivity(this, REQUEST_CODE, request)

As soon as we have a result in onActivityResult, following code is used to access the remote control (and on further app uses):

    val connectionParams = ConnectionParams.Builder(CLIENT_ID)
        .setRedirectUri(REDIRECT_URI)
        .showAuthView(false)
        .build()

    SpotifyAppRemote.connect(
        this, connectionParams,
        object : Connector.ConnectionListener {

            override fun onConnected(appRemote: SpotifyAppRemote) {
               ... //get and use the remote
            }

            override fun onFailure(throwable: Throwable) {

                when (throwable) {
                    is CouldNotFindSpotifyApp -> {
                        Toast.makeText(applicationContext, "SPT Please install Spotify first!", Toast.LENGTH_LONG).show()
                    }
                    is UserNotAuthorizedException -> {
                        authorizeAndGetSpotifyCodeViaActivityResult()
                    }
                    is SpotifyConnectionTerminatedException -> {
                        Timber.e("SPT Connection was dropped! Trying reconnecting here!")
                    }
                    else ->
                        Timber.e(throwable, "SPT Spotify onFailure!")
                }
            }
        }
    )

Steps to reproduce:

  1. it sometimes works others not, we have not found a way to constantly break it or use it

Expected behaviour:

App connects or an exception is given

Actual behaviour:

App gets stuck waiting for a connection or exception

@richardrevesz
Copy link

I think it is related to this:

#322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants