CocoaLibSpotify playback crashes after a few secon

2019-09-15 09:29发布

问题:

I followed the SimplePlayer example project while integrating it in my own test project. Logging in and searching for tracks already works perfectly, but when I try to play a song like SimplePlayer it crashes after 1-2 seconds of playback with EXC_BAD_ACCESS on two different locations in SPSession.m (see picture below). Here is the code that starts playback:

SPTrack *track = [allTracks objectAtIndex:currentTrack];
[SPAsyncLoading waitUntilLoaded:track timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedItems, NSArray *notLoadedItems) {
    [playbackManager playTrack:track callback:^(NSError *error) {
        if (error) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Can't play Spotify Track" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        } else {
            spotifyTrack = track;
        }
    }];
}];

Note: I handle the playback of the songs in a custom class SpotifyPlayer via Singleton pattern.

Any help would be greatly appreciated!

回答1:

I'm assuming SimplePlayer doesn't crash in the same way. That code shows that you're either over-releasing your SPSession instance, or that the object you set as the session's delegate has been released without the delegate being set to nil. Double check your memory management and object lifetimes.