是否有一个侦听器来侦听改变在Android上的音量? [英] Is there a listener to listen for changes in the volume in android?

查看:113
本文介绍了是否有一个侦听器来侦听改变在Android上的音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以注册一个侦听器来侦听改变音乐流Android中的音量?

Is it possible to register a listener to listen for changes in the volume level of the music stream in Android?

我显示在搜索栏的实际数量,我想改变搜索栏,如果用户改变与硬件音量键音量。目前正确的音量显示,直到用户改变与硬件按键的音量。

I'm displaying the actual volume in a SeekBar and I would like to change the seekbar if the user changes the volume with the hardware volume keys. At the moment the correct volume is displayed until the user changes the volume with hardware keys.

推荐答案

一种选择是使用<一个href="http://developer.android.com/reference/android/media/AudioManager.html#registerMediaButtonEventReceiver%28android.content.ComponentName%29">registerMediaButtonEventReceiver和你的应用程序处理的硬件按键。你可以调节音量搜索栏在您的应用程序,并使用AudioManager调节音量。

One option would be to use registerMediaButtonEventReceiver and have your application handle the hardware keys. You could adjust the volume seekbar in your app and use AudioManager to adjust the volume.

另一种可能性是创建一个在后台运行,并定期检查量,并相应地调整你的搜索栏在你的应用程序的服务。

Another possibility would be to create a service in your app that runs in the background and periodically checks the volume and adjusts your seekbar accordingly.

这篇关于是否有一个侦听器来侦听改变在Android上的音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆