简体   繁体   English

使用蓝牙耳机控制WP7和WP8应用程序

[英]Control WP7 and WP8 app with bluetooth headset

I have developed a music player app for Windows Phone 7.5 and Windows Phone 8. Now I want to listen to the music with various bluetooth devices. 我已经开发了适用于Windows Phone 7.5和Windows Phone 8的音乐播放器应用程序。现在我想用各种蓝牙设备收听音乐。 I can connect it to my phone and listen to music, so that's working just fine. 我可以将它连接到我的手机并听音乐,这样就可以了。 But it acts weird in certain scenarios. 但它在某些情况下表现得很奇怪。 If the music is paused it will resume on the speakers if I disconnect the bluetooth. 如果音乐暂停,如果我断开蓝牙,它将在扬声器上恢复。 I can see in my log that it receives a user action to UserAction.SEEK to the position it was when I turned off bluetooth. 我可以在我的日志中看到它收到UserAction.SEEK的用户操作到我关闭蓝牙时的位置。 At this point, the player.Position variable has somehow gotten to be 0, so it goes to 0 and back to where I was. 此时, player.Position变量以某种方式变为0,因此它变为0并返回到我所在的位置。 And I don't do anything that would cause that action. 而且我不做任何会导致这种行为的事情。

What I am asking: Is there a way to take over control or to get any control in the AudioPlaybackAgent that I use of what happens when I do something with my bluetooth devices. 我要问的是:有没有办法接管控制或获取AudioPlaybackAgent中的任何控制权,当我使用我的蓝牙设备时会发生什么。 Is there any event that occurs, or is all this handled by the OS? 是否有任何事件发生,或者所有这些都由操作系统处理? If so, why does my application behave differently than the stock app? 如果是这样,为什么我的应用程序的行为与股票应用程序不同? Also, why am I receiving a UserAction.SEEK when I turn of my bluetooth device? 另外,为什么我在转动蓝牙设备时收到UserAction.SEEK

If my question is unclear, please don`t hesitate to ask! 如果我的问题不清楚,请不要犹豫!

This is a known issue with the platform, but is fixed in WP8 GDR2. 这是平台的已知问题,但在WP8 GDR2中已得到修复。 You can workaround the issue by detecting an OnUserAction sequence of Pause Seek Play . 您可以通过检测Pause Seek PlayOnUserAction序列来解决此问题。 Once detected, you can pause on the next call to OnPlayerStateChanged . 检测到后,您可以暂停对OnPlayerStateChanged的下一次调用。 A few things to be aware of: 有几点需要注意:

  • Consecutive calls to OnUserAction aren't guaranteed to be called on the same instance of AudioPlayer , so any state should be stored in static state. 不能保证在同一个AudioPlayer实例上调用对OnUserAction的连续调用,因此任何状态都应该以静态存储。
  • The track will play from the speaker for a brief moment, so you might want to set the volume to 0 (after making note of it's previous value, of course) 该曲目将在短时间内从扬声器播放,因此您可能希望将音量设置为0(当然,在记录它之前的值之后)

I've posted a Gist to GitHub with a full implementation . 我已经向GitHub发布了一个完整实现Gist Example usage and a more detailed rundown of the problem is available on my blog . 我的博客上提供了示例用法和更详细的问题简介。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM