SPTTrack trackWithURI issue

369 views Asked by At

I had created the new project which fetches the track of songs, so I tried to pass an array of SPTTracks to the player, please find it below.

    self.player = [[SPTAudioStreamingController alloc] initWithClientId:auth.clientID];
    self.player.diskCache = [[SPTDiskCache alloc] initWithCapacity:1024 * 1024 * 64];

            NSString *trackURI = @"spotify:track:1zHlj4dQ8ZAtrayhuDDmkY";

            [SPTTrack trackWithURI:[NSURL URLWithString:trackURI] accessToken:auth.session.accessToken market:@"ES" callback:^(NSError *error, id object) {
                if (!error) {
                    SPTTrack *trackInfo = object;
                    NSArray *tracks = @[trackInfo];
                    [self.player playURIs:tracks fromIndex:0 callback:^(NSError *error) {
                        if (!error) {

                        } else {
                            NSLog(@"*** Failed to play track : %@", error);
                        }
                    }];
                } else {
                    NSLog(@"Error %@", error);
                }
            }];

But I get crashes, whenever I run it. Please find error below while it is getting crash :

Simple Track Playback[254:24669] -[__NSCFConstantString absoluteString]: unrecognized selector sent to instance 0x1000c0508

I had also looked it on spotify api spotify_ios_sdk but I had found that one developer had already posted the same issue link.

If anyone has solved these type of issue then please provide your guidance.

Thanks in advanced.

1

There are 1 answers

0
Ramkrishna Sharma On BEST ANSWER

Unfortunately, this method is not "equivalent", because the SPTTrack object returned inside the callback of [SPTTrack trackWithURI.... has many less informations.

I've tried some workaround, and I found that for me the solution is

1) Create a request for an SPTTrack object.

2) Pass that request to SPRequest performRequest callback.

3) Wait for the response, and eventually create a track from data (please find the below complete code).

self.player = [[SPTAudioStreamingController alloc] initWithClientId:auth.clientID];
self.player.diskCache = [[SPTDiskCache alloc] initWithCapacity:1024 * 1024 * 64];



NSString *market = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
NSURLRequest *request = [SPTTrack createRequestForTrack:[NSURL URLWithString:@"spotify:track:1zHlj4dQ8ZAtrayhuDDmkY"]
                                        withAccessToken:auth.session.accessToken
                                                 market:market
                                                  error:nil];
[[SPTRequest sharedHandler] performRequest:request
                            callback:^(NSError *error, NSURLResponse *response, NSData *data) {
                            if (!error) {
                                 NSError *parsingError = nil;
                                 SPTTrack *track = [SPTTrack trackFromData:data
                                                                   withResponse:response
                                                                          error:&parsingError];

                                          self.arrURIs = @[track.playableUri];
                                          [self.player playURIs:self.arrURIs fromIndex:0 callback:nil];

                                      }
                                  }];

Thanks "Kry256" for detail explaination.