Calling setVolumeControlStream from a Service

2019-03-17 23:05发布

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?

2条回答
我只想做你的唯一
2楼-- · 2019-03-17 23:06

I think this library can provide you what you need:

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

查看更多
手持菜刀,她持情操
3楼-- · 2019-03-17 23:08

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.

查看更多
登录 后发表回答