3

Webからmp3ファイルをストリーミングするAVPlayerがあります。AVAudioSessionをアクティブにして、アプリを終了したとき/画面をオフにしたときにオーディオが再生されるようにしました。音楽は完全に再生されますが、音楽の再生中は、電話の上部にあるステータスメニューに表示される小さな「再生」の三角形のアイコンは表示されません(iOSの通常の場合のように)。私が間違っていることはありますか?以下のコード

// 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);
4

1 に答える 1

2

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];
于 2012-07-14T00:33:23.810 に答える