如何在J2ME LWUIT中获取硬音量键事件?
我正在使用 LWUIT 构建媒体播放器应用程序。我的问题是,当用户按下设备的任何音量硬件键时,我无法增大/减小媒体播放器的音量。请帮忙。
I am having a media player application built using LWUIT. My problem is that I am unable to increase/decrease the volume of the media player when the user presses any volume hardware key of the device. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用普通的
Canvas
创建应用程序并在您的设备上运行它。在画布上的keyPressed
函数,将结果打印到屏幕上。我怀疑当您按下音量键时不会发生任何事情,在这种情况下,按下这些键时您将无法执行任何操作。Create an app with a plain
Canvas
and run it on your device. On the canvas'skeyPressed
function, print the results out to the screen. I suspect nothing will happen when you press the volume keys, in which case you have no way of doing anything when these keys are pressed.对于某些设备,您只是没有收到事件,而对于其他设备,您将获得截然不同的值,正如 funkybro 所说。您可以使用 LWUIT 应用程序进行相同的实验(不需要画布)。
Android 确实公开了音量键,但我建议避免使用它们并让它处理自己的音量,因为它在 Android 上是一个如此复杂的主题。 LWUIT 中的 RIM 实现有一个静态侦听器,您可以将其绑定到音量键事件,但这仅适用于 RIM 设备。
For some devices you just don't get an event and for others you will get wildly differing values as funkybro has stated. You can do the same experiment with a LWUIT application (no need for canvas).
Android does expose volume keys but I would recommend avoiding them and letting it handle its own volume since its such a complicated subject on Android. The RIM implementation in LWUIT has a static listener which you can bind to volume key events but this will only work on RIM devices.