【发布时间】:2014-07-07 12:22:03
【问题描述】:
我试图在谷歌中寻找它好几天,但我找不到答案。 我有一个从互联网播放音频流的应用程序,我使用 MPNowPlayingInfoCenter 来显示艺术家标题、歌曲标题和艺术品。现在我的问题是如何使用 MPNowPlayingInfoCenter 中的播放/暂停按钮来播放或停止我的音频流。
【问题讨论】:
标签: ios objective-c mpnowplayinginfocenter
我试图在谷歌中寻找它好几天,但我找不到答案。 我有一个从互联网播放音频流的应用程序,我使用 MPNowPlayingInfoCenter 来显示艺术家标题、歌曲标题和艺术品。现在我的问题是如何使用 MPNowPlayingInfoCenter 中的播放/暂停按钮来播放或停止我的音频流。
【问题讨论】:
标签: ios objective-c mpnowplayinginfocenter
为此你必须处理远程控制事件 --
//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;
}
}
}
【讨论】: