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

onPositionChanged and onPlaybackChanged not updating #2

Open
AquaCobell opened this issue Aug 25, 2023 · 6 comments
Open

onPositionChanged and onPlaybackChanged not updating #2

AquaCobell opened this issue Aug 25, 2023 · 6 comments

Comments

@AquaCobell
Copy link

After using most of the documentation code:

Main.java:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");

        SpotifyController controller = new SpotifyController("http://192.168.188.74/api/custom?name=Spotify");

        controller.register();


    }
}

SpotifyController.java

import de.labystudio.spotifyapi.SpotifyAPI;
import de.labystudio.spotifyapi.SpotifyAPIFactory;
import de.labystudio.spotifyapi.SpotifyListener;
import de.labystudio.spotifyapi.model.Track;

public class SpotifyController 
{   


    private SpotifyAPI spotify;
    Httpcontroller httpcontroller;

    SpotifyController(String url)
    {
        spotify = SpotifyAPIFactory.create();
        httpcontroller = new Httpcontroller("http://192.168.188.74/api/custom?name=Spotify");
    }

    public void register()
    {
        spotify.registerListener(new SpotifyListener() 
        {
        
            @Override
            public void onConnect() {
                System.out.println("Connected to Spotify!");
            }
            
            @Override
            public void onTrackChanged(Track track) {
                System.out.println("Track changed:" + track);
            }
            
            @Override
            public void onPositionChanged(int position) {
                /*if (!spotify.hasTrack()) {
                    return;
                }
                
                int length =spotify.getTrack().getLength();
                float percentage = 100.0F / length * position;
                
                System.out.printf(
                    "Position changed: %s of %s (%d%%)\n",
                    formatDuration(position),
                    formatDuration(length),
                    (int) percentage
                );*/

                System.out.println("Position change: " + position);
            }
            
            @Override
            public void onPlayBackChanged(boolean isPlaying) {
                System.out.println(isPlaying ? "Song started playing" : "Song stopped playing");
            }
            
            @Override
            public void onSync() {
                
            }
            
            @Override
            public void onDisconnect(Exception exception) {
                System.out.println("Disconnected: " + exception.getMessage());
                
                spotify.stop();
            }

        });

        spotify.initialize();
    }
    


}

Ive noticed it never prints "Song stopped playing" and "Position change" during songs, it only prints position change after skipping a song. Am I missing something or is this a bug?

@AquaCobell AquaCobell changed the title onPositionChanged and onPaybackChanged not updating onPositionChanged and onPlaybackChanged not updating Aug 25, 2023
@LabyStudio
Copy link
Owner

It basically means it can't find the memory address of your track position.
It works for me, and since I can't look into your memory to figure out why it fails on your machine, it's really difficult to analyze the issue.

You can verify the issue by setting the VM option -DSPOTIFY_API_DEBUG to enable debug logging.

Have you tried to restart Spotify and change playlists/songs?

@HerXayah
Copy link
Contributor

HerXayah commented Sep 8, 2023

@AquaCobell are you by chance using Spotify via Scoop or any other Package manager?

@AquaCobell
Copy link
Author

@princessakira no im using the jar file

@AquaCobell
Copy link
Author

@LabyStudio thanks i'll look into it.
Is it supposed to update every second or only when i manually forward in spotify itself?

@NULLYUKI
Copy link

@princessakira no im using the jar file

I think you misunderstood the question.
Did you installed Spotify via Scoop or any other Package manager? Or did you manually downloaded Spotify from the Spotify website?

@AquaCobell
Copy link
Author

@NULLYUKI ah sorry you're right, I got it from their website via the installer

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

4 participants