【问题标题】:cocoalibspotify: Crash during playback callback under music_deliverycocoalibspotify:music_delivery下播放回调时崩溃
【发布时间】:2013-07-16 18:40:14
【问题描述】:

我们在使用 cocoalibspotify 玩游戏时发生了崩溃: 问题看起来像在SPSession.m下的回调函数music_delivery()中,实例发起的回调不是SPSessionAudioDeliveryDelegate兼容的实例。但是,我们使用的唯一与播放相关的实例是 SPPlaybackManager。而我们之前使用Spotify播放歌曲的函数是:

#pragma mark - Domain function
- (void)searchForKeywords:(NSString *)keywords{
    //construct search string
    SPSearch *search = [[SPSearch alloc] initWithSearchQuery:keywords inSession:[SPSession sharedSession]];

    //search track
    [SPAsyncLoading waitUntilLoaded:search timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *results, NSArray *notLoadedResults) {
    if ([results count]>0) {
        //search returns results.
        SPSearch *thisSearch = [results objectAtIndex:0];
        if ([[thisSearch tracks] count]>0) {

            // Add loading flag for album art
            [[ImageManager sharedInstance] setLoadingFlagForSong:self.namedSong];

            SPTrack *track = [[thisSearch tracks]objectAtIndex:0];

            [SPAsyncLoading waitUntilLoaded:track timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *tracks, NSArray *notLoadedTracks) {

                self.currentTrack = track;
            }];
        }else{
        }

    }else{
        //search didn't return results.
    }
    }];
}

- (void)play
{
[SPSession dispatchToLibSpotifyThread:^{
    [[SPSession sharedSession]setPlaybackDelegate:self];

    // Change the current track of the session
    if (currentTrack) {

        self.playbackManager = [[SPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
        [[SPSession sharedSession]setPlaybackDelegate:self];

        [self.playbackManager playTrack:currentTrack callback:^(NSError *error) {

            // Failure playing
            if (error) {
            }
            // Success
        }];
    }

    // Play
    else {
    }
}];
}

- (void)pause
{
[SPSession dispatchToLibSpotifyThread:^{
    [SpotifyHelper sharedInstance].playbackManager.isPlaying = NO;
} waitUntilDone:YES];
}


- (void)stop
{
[SPSession dispatchToLibSpotifyThread:^{
    [SpotifyHelper sharedInstance].playbackManager.isPlaying = NO;
    [[SpotifyHelper sharedInstance].playbackManager sessionDidEndPlayback:[SPSession sharedSession]];
} waitUntilDone:YES];
}

-(void)seekToLocation:(float)location
{
[SPSession dispatchToLibSpotifyThread:^{
    [[SpotifyHelper sharedInstance].playbackManager seekToTrackPosition:location * self.currentTrack.duration];
} waitUntilDone:YES];
}

错误信息: -[__NSCFType session:shouldDeliverAudioFrames:ofCount:streamDescription:]: 无法识别的选择器发送到实例 0x21328a90

Stack:
0    libsystem_kernel.dylib  __pthread_kill + 8
1    libsystem_c.dylib   pthread_kill + 58
2    libsystem_c.dylib   abort + 94
3    libc++abi.dylib     abort_message + 74
4    libc++abi.dylib     default_terminate() + 24
5    libobjc.A.dylib     _objc_terminate() + 146
6    libc++abi.dylib     safe_handler_caller(void (*)()) + 78
7    libc++abi.dylib     std::terminate() + 19
8    libc++abi.dylib     __cxa_throw + 122
9    libobjc.A.dylib     objc_exception_throw + 94
10   CoreFoundation  __methodDescriptionForSelector
11   CoreFoundation  ___forwarding___ + 392
12   CoreFoundation  _CF_forwarding_prep_0 + 24
crash->13    OURAPP      music_delivery
14   OURAPP  sp_playlist_get_offline_download_completed
15   OURAPP  sp_error_message
16   OURAPP  sp_error_message

【问题讨论】:

    标签: ios spotify cocoalibspotify-2.0


    【解决方案1】:

    两件事:

    1) 在调用 CocoaLibSpotify 方法时不要分派到 CocoaLibSpotify 线程——这是在内部完成的。删除dispatchToLibSpotifyThread 行。

    2) 删除[[SPSession sharedSession]setPlaybackDelegate:self]; 行。这就是导致你崩溃的原因。

    【讨论】:

    • 非常感谢!所以dispatchToLibSpotifyThread不应该用在pause、stop、seektoposition的场景吧?请查看我的原始帖子以获取我的代码。
    • 另外,如果我在这里删除 setplaybackdelegate,我应该把它放在其他地方吗?就像在 -init 方法中一样。
    • 如果您不确定是否应该使用dispatchToLibSpotifyThread,请不要使用它。它很少需要,如果你确实需要使用它,库会在运行时告诉你。不,只需删除该行代码,不要将其放在其他任何地方。
    • 嗨 iKenndac,如果我们删除 setPlaybackDelegate,我们如何获得 Spotify 库的通知?我们目前正在使用它来跟踪歌曲何时通过 (-(void)sessionDidEndPlayback:(id)aSession{}) 完成播放
    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多