Calling setVolumeControlStream from a Service

徘徊边缘 提交于 2019-12-20 17:35:14

问题


I need to call setVolumeControlStream from a service that plays some sound via STREAM_SYSTEM. Obviously in an Activity that is no problem, but how can I do this with a service?


回答1:


From the looks of it, this isn't possible the way you are trying to do it.

As said in the android reference

The suggested audio stream will be tied to the window of this Activity

Hence with a service that has no activity, there is no window to tie the audio stream to.

However, It looks like you should be able to receive media key events (including volume keys) from a broadcaster as shown here which would allow you to change your service volume without an activity being visible.




回答2:


I think this library can provide you what you need:

http://code.google.com/p/media-volume-control/



来源:https://stackoverflow.com/questions/8037390/calling-setvolumecontrolstream-from-a-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!