0
我需要利用耳機按鈕按下我的應用程序以外的多媒體。這是迄今爲止我所擁有的功能,它不起作用。當我按下耳機按鈕,我的應用程序沒有響應,而不是音樂播放...檢測耳機按鈕按
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
if ([self canBecomeFirstResponder]) {
[self becomeFirstResponder];
NSLog(@"became first responder");
}
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent
{
if (theEvent.type == UIEventTypeRemoteControl) {
switch(theEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"Hello");
case UIEventSubtypeRemoteControlPlay:
NSLog(@"Hello 2");
break;
case UIEventSubtypeRemoteControlPause:
NSLog(@"Hello 3");
break;
case UIEventSubtypeRemoteControlStop:
NSLog(@"Hello 4");
break;
default:
return;
}
}
}
這是錯誤的。但是,應用程序必須具有「正在播放」狀態,只能通過播放某種形式的音頻才能達到此狀態。 –