ACTION_HEADSET_PLUG 广播延迟
我有自己的用于 Intent.ACTION_HEADSET_PLUG
操作的 BroadcastReceiver
实例。实际物理拔出耳机与我的 BroadcastReceiver
收到通知之间大约有 1-2 秒的延迟。
IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// my code here
}
}, filter);
有什么想法可以减少延迟吗?
I have my own BroadcastReceiver
instance for Intent.ACTION_HEADSET_PLUG
action. There is about 1-2 seconds delay between actual physical unplugging a headset and a moment when my BroadcastReceiver
is notified about that.
IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// my code here
}
}, filter);
Any ideas how to decrease the delay?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理 AudioManager.ACTION_AUDIO_BECOMING_NOISY 广播就达到了目的:)它的意图是在耳机拔出后直接广播,没有任何延迟。
Handling
AudioManager.ACTION_AUDIO_BECOMING_NOISY
broadcast did the trick :) Its intent is broadcast directly after headset is unplugged without any delay.你运气不好。
延迟是在框架中硬编码的,查看
延迟为 1000 毫秒,因为音频管道中存在垃圾的风险。
You are out of luck.
The delay is hardcoded in the framework, look in
The delay is 1000 ms, due to the risk of having garbage in the audio pipeline.