gpt4 book ai didi

ios - 应用程序图标不会显示在应用程序切换器的音乐控件中

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:34 24 4
gpt4 key购买 nike

我正在编写一个流式传输音乐的应用程序,但我在设置音乐控制停靠屏幕上的图标时遇到了很多麻烦(当您双击主页按钮并向左滑动时)。所有文档都说要做这样的事情,但图标从未出现,我也从未收到过事件通知。所有这些代码都在我的播放器 View Controller 中。 _radioPlayer 是 AVQueuePlayer 的一个实例。我在这里做错了什么?

- (void)viewWillAppear:(BOOL)animated
{
UIApplication *application = [UIApplication sharedApplication];
if([application respondsToSelector:@selector(beginReceivingRemoteControlEvents)])
[application beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

- (BOOL)canBecomeFirstResponder
{
return YES;
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[_radioPlayer pause];
break;
case UIEventSubtypeRemoteControlPlay:
[_radioPlayer play];
break;
case UIEventSubtypeRemoteControlPause:
[_radioPlayer pause];
break;
default:
break;
}
}

编辑:我通读了 documentation并按照步骤操作,但仍然无法正常工作。以下是我想出的一些可能原因:

一个。调用 viewDidAppear 时,我的音乐尚未播放。在文档中它指出

"Your app must be the “Now Playing” app. Restated, even if your app is the first responder >and you have turned on event delivery, your app does not receive remote control events until >it begins playing audio."

我尝试在音乐开始播放后调用 beginReceivingRemoteControlEvents:becomeFirstResponder: 但这也不起作用。这些只能在 viewDidAppear: 中调用吗? iOS 是否会自动检测音乐何时开始播放,所以这不是必需的?

B.使用 AVQueuePlayer 有一些奇怪的地方。我几乎可以肯定不是这样,因为事件消息是由 View Controller 处理的,而不是播放器本身。

最佳答案

它可能对您不起作用,因为您在 viewWillAppear 而不是 viewDidAppear 中调用 beginReceivingRemoteControlEvents。查看documentaion -

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

// Turn on remote control event delivery

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}

关于ios - 应用程序图标不会显示在应用程序切换器的音乐控件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15846545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com