2015-07-05 118 views
0

我想在我的應用程序來播放聲音(使用SWIFT), 在didFinishLaunchingWithOptions功能我寫這 的iOS 8,AVPlayer背景音樂播放,remoteControlReceivedWithEvent不叫

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil) 
AVAudioSession.sharedInstance().setActive(true, error: nil) 

,我有一個UIView持有的AVPlayer

我用:

UIApplication.sharedApplication().beginReceivingRemoteControlEvents() 
self.becomeFirstResponder() 

remoteControlReceivedWithEvent功能。當應用程序進入後臺時,聲音會繼續播放,但是當我點擊暫停按鈕(我們用來播放並暫停應用程序外的聲音)時,remoteControlReceivedWithEvent永遠不會被調用!

怎麼了?

回答

1

在我的項目: 我稱這種現象UITabbarViewController

-(BOOL)canBecomeFirstResponder{ 
    return YES; 
} 
-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
    [self becomeFirstResponder]; 
} 

確保它能夠成爲第一個響應。 remoteControlReceivedWithEvent in AVAudio is not being called

+0

感謝這是caBecomeFirstREsponder問題:D – user3703910