是否有监听器可以监听 android 中音量的变化? [英] Is there a listener to listen for changes in the volume in android?

查看:32
本文介绍了是否有监听器可以监听 android 中音量的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我在 SeekBar 中显示实际音量,如果用户使用硬件音量键更改音量,我想更改搜索栏.目前显示正确的音量,直到用户使用硬件键更改音量.

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.

推荐答案

一种选择是使用 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天全站免登陆