我们如何在iOS的前景中处理耳机播放/暂停按钮事件 [英] How can we handle headphone play/pause button events in foreground in ios
本文介绍了我们如何在iOS的前景中处理耳机播放/暂停按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要求在前台处理耳机播放/暂停按钮事件.如何使用下面的代码在后台处理相同的情况
I have an requirement that to handle headphone play/pause button events in foreground. How ever I am able to handle the same scenario in background using the below code
if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
[self becomeFirstResponder];
NSLog(@"Responds!");
}
请尽可能提供说明或示例代码.我做了很多研究但没有帮助.
Please help with an explanation or sample code if possible. I have done lots of research but no help.
推荐答案
还有另一种通过耳机实现播放器控制的方法.
使用MPRemoteCommandCenter
tooglePlayPauseCommand.
Apple文档
There is another way to implement player control from headphones.
use MPRemoteCommandCenter
tooglePlayPauseCommand.
Apple documentation
[[MPRemoteCommandCenter sharedCommandCenter].togglePlayPauseCommand addTarget:self action:@selector(onTooglePlayPause)];
这篇关于我们如何在iOS的前景中处理耳机播放/暂停按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文