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

Switching between spotify accounts #8

Open
JohanCosemans opened this issue Feb 23, 2015 · 0 comments
Open

Switching between spotify accounts #8

JohanCosemans opened this issue Feb 23, 2015 · 0 comments

Comments

@JohanCosemans
Copy link

Hello nvdweem,

I'm using your library in a project and I would like to add the possibilty to switch from spotify account. What I would like to achieve is to logout/shutdown the current spotify session and start a new one with another account. I have tried all the logout/shutdown/destroy methods of JahSpotifyService and the jahspotify instance, but never manage to do this.

I adjusted the test application to try this:

public static void main(String[] args) {        
    // Determine the tempfolder and make sure it exists.
    File temp = new File(new File(Main.class.getResource("Main.class").getFile()).getParentFile(), "temp");
    temp.mkdirs();

    // Start JahSpotify
    JahSpotifyService.initialize(temp);
    JahSpotifyService.getInstance().getJahSpotify().addConnectionListener(new AbstractConnectionListener() {
        @Override
        public void initialized(final boolean initialized) {
            if (initialized)
                JahSpotifyService.getInstance().getJahSpotify().login(uname1, password1, null, false);
        }

        @Override
        public void loggedIn(final boolean success) {
            if (success) {
                System.out.println("Logged in as "+JahSpotifyService.getInstance().getJahSpotify().getUser().getUserName());
            }
        }

       @Override
       public void playlistsLoaded(final boolean contents) {
           System.out.println("Found "+PlaylistContainer.getPlaylists().size()+" playlists");
       }

       public void loggedOut() {
           System.out.println("Logged out from spotify");
       }
    });

    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }

    // Shutdown, logout, ... from spotify
    JahSpotifyService.getInstance().shutdown();

    // Login with a new user when typing y (after logout)
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String result = null;
    try {
        while(true) {
            System.out.println("Switch user? (y or n)");
            result = in.readLine();
            if(result.equals("y")) {
                JahSpotifyService.getInstance().getJahSpotify().login(uname2, password2, null, false);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

This results in:

feb 23, 2015 6:37:29 PM jahspotify.impl.NativeLogger error
SEVERE: [jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser] Retrieving user
feb 23, 2015 6:37:29 PM jahspotify.impl.NativeLogger error 
SEVERE: [jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser] User is loaded
Logged in as 124884048
Found 64 playlists
Switch user? (y or n)
Logged out from spotify
feb 23, 2015 6:37:34 PM jahspotify.impl.NativeLogger info
INFO: [callbacks::signalLoggedOut] Logout signalled
y
Switch user? (y or n)
Logged in as 124884048
y
Switch user? (y or n)
Logged in as 124884048

Note that the user ID is always the same. Also the playlists of the second account are never loaded.

Do you know how this can be done?

Thanks for publishing this library and thanks in advance for your help.

Kind regards,
Johan

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

1 participant