rinukkusu / spotify-dart

A dart library for interfacing with the Spotify API.
BSD 3-Clause "New" or "Revised" License
191 stars 91 forks source link

404 Device not found (and unhandled exception) #191

Closed cudajo closed 5 months ago

cudajo commented 6 months ago

Suddenly from nowhere (?) I have been running into issues with devices (especially iPhones) not keeping their connection to Spotify.

After making sure that the Spotify app have been started/activated on the iPhone, I call SpotifyApi.player.devices() from my app. The iPhone is then one of the devices that is returned in the list. After a few seconds when calling SpotifyApi.player.startOrResume(...) to play a track on the specific device id, the API returns the call with 404 Device not found or just 404 not found. Checking the active devices through SpotifyApi.player.devices(), the iPhone device is no longer in the list...

Having googled for this, it seems like a fairly common issue and something that seems to pop up now and then? This issue does not happen with my laptop, as it is "always" in the list of available devices and also possible to target as device for playing a track - no matter how long time has passed. Anyone with any idea(s) of how to solve this?

On a separate note, and more specifically related to this library... In the scenario above (trying to play a track on an unavailable device) I get the below unhandled exception. Seems like the following call to PlayerEndpoint.playbackState returns an empty string that isn't handled by the library:

404 : Not found.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Unexpected end of input (at character 1)

^

#0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
#1      _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:501:7)
#2      _parseJson (dart:convert-patch/convert_patch.dart:36:10)
#3      JsonDecoder.convert (dart:convert/json.dart:610:36)
#4      JsonCodec.decode (dart:convert/json.dart:216:41)
#5      PlayerEndpoint.playbackState (package:spotify/src/endpoints/player.dart:39:22)
<asynchronous suspension>
#6      SpotifyService.play (package:spodj/services/spotify_service.dart:497:22)
<asynchronous suspension>

Thanks!

rinukkusu commented 5 months ago

PlaybackState issue is fixed with v0.13.1 🚀

Regarding your initial issue we probably can't help you. 😢