如何在macOS上检测远程音频按钮? [英] How to detect remote audio buttons on macOS?

查看:74
本文介绍了如何在macOS上检测远程音频按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文章处理外部玩家事件通知苹果公司说您需要这样做:

In the article Handling External Player Events Notifications Apple says that you need to do this:

•使用共享的MPRemoteCommandCenter对象注册要处理的事件的处理程序,并禁用您不希望接收的事件.

• Use the shared MPRemoteCommandCenter object to register handlers for the events you wish to handle and to disable the events you are not interested in receiving.

•开始播放音频.您的应用程序必须是正在播放"应用程序.应用开始播放音频之前,不会接收远程控制事件.使用Control Center来测试您的应用是否正确接收和处理了远程控制事件,您可以通过从屏幕底部向上滑动来访问该事件.这些控件将远程控制事件发送到当前或最近播放音频的应用程序.您还可以从设备的锁定屏幕访问播放控件.

• Begin playing audio. Your app must be the Now Playing app. An app does not receive remote control events until it begins playing audio. Test that your app is properly receiving and handling remote control events with Control Center, which you access by swiping up from the bottom edge of your screen. These controls send remote control events to the app that is currently or was most recently playing audio. You can also access the playback controls from the lock screen of the device.

第二部分只能在iOS上应用,并且可以在iOS上运行.但是,不确定如何在macOS上处理此问题.我认为需要设置的一件事是设置 MPNowPlayingInfoCenter .但是无法在macOS的控制中心"中检查它,我想唯一的方法是通过检查TouchBar音频控件,但是似乎在那里没有效果.因此,可能需要在iOS上设置 AVAudioSession 之类的东西,但在macOS上找不到类似的东西.而且文件几乎不存在.

The second part can be applied only on iOS and it works there. However, not sure how to handle this on macOS. I would assume that one thing needed to set is to set MPNowPlayingInfoCenter. But it can't be checked in the Control Center on macOS, I would guess that the only method is by checking the TouchBar audio controls, but it doesn't seem to have effect there. So probably there is a need to set something like AVAudioSession on iOS, but I can't find anything similar on macOS. And documentation is almost non-existent.

请注意,我在文本语音转换应用中使用了此代码,因此无法使用某些API,例如 AVPlayer .

Note that I am using this in the text to speech app so I can't use some APIs like AVPlayer.

推荐答案

我找到了答案-是的,它足以设置 MPNowPlayingInfoCenter ,关键部分是设置 playbackState .

I found the answer - yes it is enough to set MPNowPlayingInfoCenter, the critical part is to set playbackState.

这篇关于如何在macOS上检测远程音频按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆