我正在尝试通过我的应用程序流式传输 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;
}
}