【问题标题】:how to overide play/pause button in MPNowPlayingInfoCenter如何覆盖 MPNowPlayingInfoCenter 中的播放/暂停按钮
【发布时间】:2014-07-07 12:22:03
【问题描述】:

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

【问题讨论】:

标签: ios objective-c mpnowplayinginfocenter


【解决方案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;
    }
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 2016-10-25
    • 2019-06-25
    • 2022-06-28
    • 2014-12-05
    相关资源
    最近更新 更多