MPNowPlayingInfoCenter Disappears when audio stream stalls MPNowPlayingInfoCenter Disappears when audio stream stalls ios ios

MPNowPlayingInfoCenter Disappears when audio stream stalls

If I were to take a guess (and it's been a while since I've used AVFoundation) I would assume your audio session is being deactivated by the OS as soon as data stop flowing through the audio buffer. One trick would be to maintain a second AVPlayer which plays back silence to fill in the dead spots until you've buffered enough data to resume playback or reached some timeout and just give up. Use the notification to switch between player objects.

I am not getting any issue when set the lock screen even in network problem.

I am also dealing with streaming.

And I think lock screen only affected when audio session is active or not.

Here you can see my code and I am not getting any issue hope this will help to you.

-(void)setLockScreen{    Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");    if (playingInfoCenter)    {        [[AVAudioSession sharedInstance] setActive:YES error:nil];        NSError *myErr;        if (![[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&myErr])        {            // Handle the error here.            NSLog(@"Audio Session error %@, %@", myErr, [myErr userInfo]);        }        else        {            [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];            [self becomeFirstResponder];        }        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:imgViewLogo.image];        NSArray *keys = [NSArray arrayWithObjects:                         MPMediaItemPropertyTitle,                         MPMediaItemPropertyArtist,                         MPMediaItemPropertyArtwork,                         MPNowPlayingInfoPropertyPlaybackRate,                         nil];        NSArray *values = [NSArray arrayWithObjects:                           [[self.arrChannel objectAtIndex:[AppDelegate sharedAppDelegate].selectedRow] objectForKey:@"name"],                           [[AppDelegate sharedAppDelegate].dictChannelsConfig objectForKey:@"venueName"],                           albumArt,                           [NSNumber numberWithInt:1],                           nil];        NSDictionary *mediaInfo = [NSDictionary dictionaryWithObjects:values forKeys:keys];        keys = nil;        values = nil;        albumArt = nil;        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];        mediaInfo = nil;    }}