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?
Call creation and start are synchronous. The call instance allows you to subscribe to call events. To call another Communication Services user, use the startCall method on callAgent and pass the recipient's CommunicationUserIdentifier that you created with the Communication Services administration library.
This allows users to control the volume of each stream independently. By default, pressing the volume control modifies the volume of the active audio stream. If your app isn't currently playing anything, hitting the volume keys adjusts the music volume (or the ringer volume before Android 9).
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. Thanks for contributing an answer to Stack Overflow!
To create and start a call, use one of the APIs on callAgent and provide a user that you've created through the Communication Services identity SDK. Call creation and start are synchronous. The call instance allows you to subscribe to call events.
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.
I think this library can provide you what you need:
http://code.google.com/p/media-volume-control/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With