从一个服务调用setVolumeControlStream [英] Calling setVolumeControlStream from a Service

查看:305
本文介绍了从一个服务调用setVolumeControlStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用 setVolumeControlStream 从通过 STREAM_SYSTEM 播放一些声音的服务。 显然,在一个活动,是没有问题的,但我怎么能做到这一点的,服务?

解决方案

从外观上来看,这是不可能的,你正在尝试做的方式。

正如<一说href="http://developer.android.com/reference/android/app/Activity.html#setVolumeControlStream%28int%29"相对=nofollow标题=Android的参考>

  

建议的音频流将被捆绑到这一活动的窗口

因此​​,与不具有活性的服务,没有窗户,以配合音频流。

不过,它看起来像你应该能够从广播接收媒体键事件(包括音量键),如图所示的此处这样可以让你改变你的业务量没有一个活动是可见的。

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?

解决方案

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.

这篇关于从一个服务调用setVolumeControlStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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