我试图在谷歌中寻找它好几天,我无法找到答案。 我有一个从互联网播放音频流的应用程序,我使用MPNowPlayingInfoCenter显示艺术家标题,歌曲标题和艺术品。现在我的问题是如何使用MPNowPlayingInfoCenter中的播放/暂停按钮来播放或停止我的音频流。
答案 0 :(得分:1)
为此你必须处理遥控事件 -
//Add these lines in viewDidAppear()
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
//Add these lines in viewWillDisappear()
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
然后使用
-(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
NSLog(@"received event!");
if (receivedEvent.type == UIEventTypeRemoteControl)
{
switch (receivedEvent.subtype)
{
case UIEventSubtypeRemoteControlPlay:
// play the video
break;
case UIEventSubtypeRemoteControlPause:
// pause the video
break;
case UIEventSubtypeRemoteControlNextTrack:
// to change the video
break;
case UIEventSubtypeRemoteControlPreviousTrack:
// to play the privious video
break;
default:
break;
}
}
}