在 Monotouch 中使用 BeginReceivingRemoteControlEvents
我已经让我的应用程序在后台播放音乐,我还通过调用 BeginReceivingRemoteControlEvents 成功使其成为媒体播放器。但是,RemoteControlReceived 方法永远不会被调用。 Objective C 中的相同逻辑运行良好。任何样品或指南表示赞赏。
I've made my app play music in the background, I also successfully made it become the media player by calling BeginReceivingRemoteControlEvents. however, the RemoteControlReceived method never gets called. the same logic in Objective C is working fine. Any samples or guidelines appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要确保将其放置在第一响应者视图上,如果没有,则事件需要沿着响应者链向上传递,直到到达远程事件。尝试将远程控制事件想象为与键盘上的按键相同。例如,如果应用程序专注于按钮,并且您按下某些键盘按键,则不会发生任何事情,因为按钮不会监听按键操作。
您的代码中也出现了类似的情况。尝试使用 BeginReceivingRemoteControlEvents 和方法重写来创建一个基本的单视图项目以接收事件(不记得它是什么,RemoteEventReceived() 或类似的东西。)当您按下远程按钮时,应该会触发该事件。
(抱歉,我无法提供示例代码,目前不在 mac 前面)
You need to ensure it is placed on the First responder view, and if not, the event needs to be passed up along the chain of responders until it reaches your remote events. Try to imagine remote control events the same as keypresses on the keyboard. For example, If the app is focused on a button, and you press some keyboard keys, nothing will happen, as a button isn't listening for key presses.
A similar situation is occurring in your code. Try to create a basic, single viewed project with the BeginReceivingRemoteControlEvents and the method override to receive the event (cant remember what it is, RemoteEventReceived() or something similar.) This should get fired when you press a remote button.
(sorry I cant give sample code, not in front of mac at the minute)
您可能想尝试使用稍后的机制来侦听远程控制事件。例如,如果您想听耳机按钮:
或者,如果您更喜欢使用方法而不是块:
要停止:
或:
您需要将其添加到文件的包含区域:
这适用于背景,仅当您是在后台播放的音频应用程序时(即您必须在应用程序功能中设置该背景模式)。
You might want to try using a later mechanism to listen for remote control events. For example, if you want to listen to the headset button:
or, if you prefer to use a method instead of a block:
To stop:
or:
You'll need to add this to the includes area of your file:
This works in the background, ONLY if you are an audio app playing in the background (i.e. you have to set that background mode in your app capabilities).