Announcements

Help Wizard

Step 1

NEXT STEP

Internal Server Error on Get Playback State

Internal Server Error on Get Playback State

Plan

Free

Country

Italy

Device

PC

Operating System

Windows 10

 

My Issue

Hello, i just created a java software that should count the time i spend listening music on spotify, it requests every second the playback state and then update the time with an algorithm, it works very well, but just sometimes, (it seems when im not listening spotify) it throws internal server error

 

 

EDIT: I just noticed that sometimes throws a Service Unavailable and Bad Gateway error too

Reply
2 Replies

Could you provide some more information on what exactly are you doing with the data you are providing?

Sure, so this is the code that i use in a Runnable that runs every second

CurrentlyPlayingContext ctx = api.getInformationAboutUsersCurrentPlayback().build().execute();

            if(ctx == null)
                return;

            if(!ctx.getIs_playing()) {
                current = new SavingTrack(ctx.getItem().getId());
                current.setProgress(ctx.getProgress_ms());
                return;
            }
            if(ctx.getItem() == null) return;

            String id = ctx.getItem().getId();
            if(current != null){
                if(current.getId().equals(id)){
                    if(current.getProgress() < ctx.getProgress_ms())
                        current.setProgress(ctx.getProgress_ms());
                    return;
                } else {
                    total += current.getProgress();

                    writeTotal();
                }
            }

            current = new SavingTrack(ctx.getItem().getId());
            current.setProgress(ctx.getProgress_ms());

 Saving track is just a class with the id of the song and the progress in milliseconds, i use it for save the current track playing, when the track that i get from the request is different from the track in memory (current), i save the time on the file and change the current track.

 

The CurrentPlayingContext comes from this library 

Suggested posts