2

I'm attempting to play the top tracks from the result of an SPArtistBrowse using cocoalibspotify. Most of the time this works flawlessly, but occasionally I get the following error:

Error Domain=com.spotify.CocoaLibSpotify.error Code=3 "The track cannot be played"

This happens only for specific tracks, and for affected tracks it is consistent and repeatable (e.g. the top track for Armin van Buren, spotify:track:6q0f0zpByDs4Zk0heXZ3cO, always gives this error when attempting to play using the code below). The odd thing is, if I use the simple player sample app and enter an affected track's URL, the track plays fine; so my hunch is it has something to do with the track being loaded from an SPArtistBrowse.

Here is the code I am using to play tracks:

- (void)playTrack
{   
    SPTrack *track = [self.artistBrowse.topTracks objectAtIndex:self.currentTrackIndex];

    [SPAsyncLoading waitUntilLoaded:track then:^(NSArray *tracks) {
        [self.playbackManager playTrack:track callback:^(NSError *error) {

            if (error) {
                self.currentTrackIndex++;
                if (self.currentTrackIndex < self.artistBrowse.topTracks.count) {
                    [self playTrack];
                } else {
                    [self.activityIndicator stopAnimating];
                    self.activityIndicator.alpha = 0;
                    self.nowPlayingLabel.text = @"Spotify Error";
                }
            } else {
                [self.activityIndicator stopAnimating];
                self.activityIndicator.alpha = 0;
                self.nowPlayingLabel.text = track.name;

                // Set "Now Playing" info on the iOS remote control
                MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter];
                NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
                [dic setValue:track.name forKey:MPMediaItemPropertyTitle];
                [dic setValue:self.artistLabel.text forKey:MPMediaItemPropertyArtist];
                infoCenter.nowPlayingInfo = dic;
            }
        }];
    }];
}
Matt Bridges
  • 48,277
  • 7
  • 47
  • 61

1 Answers1

0

The artist browse should affect anything - a track is a track. However, if you can reliably reproduce it, please fork CocoaLibSpotify and add a failing unit test to the unit test suite - that way we can fix it.

It's also possible that the Spotify playback service was unavailable right at the wrong time, but that's a fairly rare occurrence.

iKenndac
  • 18,730
  • 3
  • 35
  • 51