0

我正在尝试通过我的应用程序流式传输 Deezer 收音机,但只能播放第一首曲目,并且当我想在第一个曲目播放完毕后播放其他曲目时无法获得任何回调(playerstate -> 已完成)。当我再次调用grabStream 时,我不会通过DeezerSessionRequestDelegate 方法。任何帮助,将不胜感激。谢谢。

以下是使用的主要方法:

-(void)grabStream{
    [[DeezerSession sharedSession] requestRadioForListening:kRadioId];
}
#pragma mark - DeezerSessionRequestDelegate

- (void)deezerSessionRequestDidReceiveResponse:(NSData *)data {
    NSLog(@"deezerSessionRequestDidReceiveResponse");
    NSDictionary* dictionary = [data objectFromJSONData];
    DeezerTrack* track = [[DeezerTrack alloc] initWithDictionary:dictionary];

    if ([_delegate respondsToSelector:@selector(onGetStream:forTrackId:)]) {
        NSString* stream = [dictionary objectForKey:@"stream"];
        if ([stream isKindOfClass:[NSString class]]) [_delegate onGetStream:stream forTrackId:[track deezerID]];
    }

    [track release];
}

- (void)deezerSessionRequestDidFailWithError:(NSError*)error {
    NSLog(@"deezerSessionRequestDidFailWithError");
}

在另一个班级

#pragma mark - DeezerGrabberDelegate

- (void)onGetStream:(NSString *)stream forTrackId:(NSString *)trackId{
    NSLog(@"onGetStream :: previous stream track id :: %@ next track id :: %@",     _currentStreamTrackId, trackId);

    if(![trackId isEqualToString:_currentStreamTrackId]){
         _currentStreamTrackId = trackId;
        [[DeezerAudioPlayer sharedSession] initPlayerForRadioWithDeezerId:trackId stream:stream];

    }

 }


#pragma mark - DeezerAudioPlayerDelegate

 -(void)playerStateChanged:(DeezerPlayerState)playerState{
    NSLog(@"playerStateChanged :: %i", playerState);

    switch (playerState) {
        case DeezerPlayerState_Initialized :
        case DeezerPlayerState_Ready :            
        case DeezerPlayerState_Playing :
        case DeezerPlayerState_Paused :
        case DeezerPlayerState_WaitingForData :
        case DeezerPlayerState_Stopped :break;
        case DeezerPlayerState_Finished :
            NSLog(@"+++++++++++++End of track, we're going to play another one");
            [self.grabber grabStream];

            break;
    }

}
4

2 回答 2

1

以下是使用 Deezer iOS SDK 流式传输收音机的步骤:

  • 使用 current = true 调用 requestRadioForListening 以检索当前歌曲,然后将其流式传输
  • 在歌曲完成之前,您应该在曲目结束前大约 20 秒再次调用 current = true 相同的方法,这将为您提供有关下一首曲目的信息
  • 歌曲完成后,播放您刚刚检索到的歌曲

并循环。

于 2014-02-24T14:30:55.643 回答
0

我正在努力解决同样的问题。事情是

-(void)playerStateChanged:(DeezerPlayerState)playerState

玩家状态在

DeezerPlayerState_Finished

从另一个线程(不是主线程)调用,Deezer SDK 是罪魁祸首。

解决方案很简单,在您的 switch 语句中确保使用“performSelectorOnMainThread”调用 [self.grabber grabStream],就像这样

[self.grabber performSelectorOnMainThread:@selector(grabStream) withObject:nil waitUntilDone:false];
于 2014-05-26T14:40:05.120 回答