-1

我试图在谷歌中寻找它几天,但我找不到答案。我有一个从互联网播放音频流的应用程序,我使用 MPNowPlayingInfoCenter 来显示艺术家标题、歌曲标题和艺术品。现在我的问题是如何使用 MPNowPlayingInfoCenter 中的播放/暂停按钮来播放或停止我的音频流。

4

1 回答 1

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;
    }
}

}

于 2014-07-07T12:50:42.503 回答