3
votes

I have an AVPlayer to stream an mp3 file from the web. I have activated an AVAudioSession so that the audio will play when the app is exited / screen turned off. The music plays perfectly, but the little 'Play' triangle icon that appears in the status menu at the top of the phone is not appearing when the music is playing (as is the usual case in iOS). Anything I'm doing wrong? Code below

// Set AudioSession
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

//Direct audio to speakers when there is no headphone
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
1

1 Answers

2
votes

For those who may come across this question, I figured it out. You have to make your player's controller the first responder - specifically for remote control events. Not only does this allow you to receive the remote control events (like the universal play/pause/forward/back controls), but it also puts the play icon in the status menu.

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];