如何让我的应用程序与锁定屏幕上的媒体控制按钮配合使用?

发布于 2024-12-21 08:48:18 字数 298 浏览 1 评论 0原文

在最近的 iOS 版本中,应用程序可以对锁定屏幕上的媒体控制按钮进行某种访问,例如播放/暂停按钮:

enter图片描述在这里

看起来这些按钮应该与 MPMusicPlayerController 类一起使用,是吗?有没有办法从按钮获取“原始”事件?因为音乐播放器似乎只提供了一个 API 来提供一堆 MPMediaItem 。例如,如果我的应用程序是一个需要以不同方式处理按钮的收音机,该怎么办?

In recent iOS versions apps have some kind of access to the media control buttons on the lock screen, like the Play/Pause button:

enter image description here

It looks like the buttons are supposed to work with the MPMusicPlayerController class, is that right? Is there a way to get the “raw” events from the buttons? Because the music player only seems to offer an API to supply a bunch of MPMediaItems. What if my app is for example a radio that needs to handle the buttons differently?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2024-12-28 08:48:18

经过更多搜索后,我发现这个相关问题使事情变得清晰。音乐播放器控制器类并不是真正正确的轨道,技巧是在控制器中订阅远程事件:

- (void) viewDidAppear: (BOOL) animated
{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (BOOL) canBecomeFirstResponder
{
    return YES;
}

- (void) remoteControlReceivedWithEvent: (UIEvent*) event
{
    // see [event subtype] for details
}

After a bit more searching I have found this related question that makes things clear. The music player controller class is not really the right track, the trick is to subscribe for remote events in your controller:

- (void) viewDidAppear: (BOOL) animated
{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (BOOL) canBecomeFirstResponder
{
    return YES;
}

- (void) remoteControlReceivedWithEvent: (UIEvent*) event
{
    // see [event subtype] for details
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文