Simon
Simon

Reputation: 1823

Spotify - Getting Track From URI null data

I'm developing a Spotify app and am getting null data in tracks I'm retrieving through models.Track.fromURI('uri'); If I try to access any standard data on the track (eg track.album) I get a null reference to the variable. The only thing I seem to be able to access is track.uri. Oddly, outputting the track to the console shows all data is present.

This only happens on two occasions, my first calls of models.Track.fromURI when the app loads (reloading the app fixes the problem). And when doing the same on tracks retrieved from a search (this is the deprecated sp.core.search, so that may be the issue here).

It would appear to be an odd bug, but I can't be sure.

Thanks for the help!

Upvotes: 0

Views: 497

Answers (1)

iKenndac
iKenndac

Reputation: 18776

Make sure you're waiting until the track has loaded before accessing metadata.

models.Track.fromURI('uri', function (track) {
    // Track has loaded!
});

Upvotes: 2

Related Questions