Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling setVolumeControlStream from a Service

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?

like image 564
Force Avatar asked Nov 07 '11 13:11

Force


People also ask

How do I call another communication services user using startcall?

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.

How do I control the volume of each stream independently?

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).

Is it possible to change service volume without activity being visible?

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!

How do I create and start a call from a user?

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.


2 Answers

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.

like image 116
Guykun Avatar answered Sep 28 '22 13:09

Guykun


I think this library can provide you what you need:

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

like image 45
Yossi Avatar answered Sep 28 '22 12:09

Yossi