Question

I'm trying to stream a Deezer radio through my app but can only play the first track and can't get any callback when I want to play others after the first one has finished playing (playerstate -> finished). When I call again grabStream, I don't go through DeezerSessionRequestDelegate methods. any help would be appreciated. Thanks.

Here are the main methods used :

-(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");
}

and in another class

#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;
    }

}
Was it helpful?

Solution 2

I was struggling with the same problem. The thing is

-(void)playerStateChanged:(DeezerPlayerState)playerState

with player state in

DeezerPlayerState_Finished

gets called from another thread (not main thread) and the Deezer SDK is the one to blame.

Solution is simple, in your switch statement make sure [self.grabber grabStream] is invoked using 'performSelectorOnMainThread', like so

[self.grabber performSelectorOnMainThread:@selector(grabStream) withObject:nil waitUntilDone:false];

OTHER TIPS

Here are the steps to follow to stream a radio using the Deezer iOS SDK:

  • call requestRadioForListening with current = true to retrieve the current song and then stream it
  • before the song is finished, you should call the same method with current = true again about 20sec before the end of the track, that will give you info about the next track
  • once the song if finished, stream the one you just retrieved

and loop on that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top