CocoaLibSpotify resets offline available tracks to

2019-08-30 05:20发布

问题:

I'm having a problem with CocoaLibSpotify when trying to save my playlists for offline use.

So I install my app, log in for the first time, select a playlist and set it for offline use, immediately its offlineStatus changes to SP_PLAYLIST_OFFLINE_STATUS_DOWNLOADING, all the tracks in the playlist have their offlineStatus changed to SP_TRACK_OFFLINE_WAITING, they start downloading one at a time and eventually their offlineStatus changes to SP_TRACK_OFFLINE_DONE. I turn off my wifi and I can play the downloaded tracks offline.

When I close the app and log in again, the tracks that were previously available offline now have their offlineStatus changed to SP_TRACK_OFFLINE_WAITING and can no longer be played offline. CocoaLibSpotify stores the downloaded playlists in the NSCachesDirectory, if I check that folder I see that the content hasn't changed and the track data is still there.

Another strange thing, I assume that, even in online mode, CocoaLibSpotify will play the downloaded track from the device if it's available offline. If I turn on wifi and I start playing on of these previously downloaded SP_TRACK_OFFLINE_WAITING tracks, then quickly turn off wifi, it still continues to play the entire track.

So from the looks of it, I'm assuming the tracks still remain offline but for some reason their offlineStatus gets the wrong status when logging in. And that the session refuses to start playing the track because of its offlineStatus.

But how can I avoid the tracks having their offlineStatus reset or at the very least, correct the problem when I know the track has been downloaded. I've tried setting the offlineStatus to SP_TRACK_OFFLINE_DONE manually but that didn't work. I'm hoping someone can shed some light on this.

Thanks in advance.

回答1:

Manually setting the property won't affect anything but your UI.

There's a couple of things to check:

  • When you quit your application, make sure you logout ([SPSession -logOut]) and wait until the logout completes before letting the application die, otherwise you might get a broken cache.

  • When you log back in again, are you using CocoaLibSpotify's saved credentials or manually entering your password again? If it's the latter, it won't work since the library can't contact the Spotify service to verify the credentials. Using CocoaLibSpotify's built-in credential saving doesn't have this problem.



标签: ios spotify