如何在我自己的应用程序中使用锁屏iPod控件?
我尝试了MPNowPlayingInfoCenter,但如果我设置了信息,它就不会在任何地方显示;不在锁屏上,也不在AppleTV上播放。
我使用AVPlayer播放我的音频文件。
答案 0 :(得分:12)
查看Remote Control of Multimedia文档。
以下是如何在UIViewController
子类中侦听远程控制事件。首先,让您的控制器参与响应者链,否则事件将转发给应用程序代表:
- (BOOL)canBecomeFirstResponder
{
return YES;
}
在适当的情况下,告诉应用程序开始接收事件并使控制器成为第一响应者:
// maybe not the best place but it works as an example
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
然后回复他们:
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[self playOrStop: nil];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
[self previousTrack: nil];
break;
case UIEventSubtypeRemoteControlNextTrack:
[self nextTrack: nil];
break;
default:
break;
}
}
}