J.-B. C.
J.-B. C.

Reputation: 872

Set the volume control stream from a service on Android

I'm working on a music app which consists in a Service playing music while other apps are running.

In order to enjoy the music and only the music, the Service mutes all the other apps. In order to do that, it mutes STREAM_MUSIC and play music over STREAM_VOICE_CALL (found that solution to mute other apps here)

As the Service uses STREAM_VOICE_CALL to play music, what I'm trying to find is a way to make the volume buttons control this stream when a sound is playing.

What I already tried:

At this point, I'm out of options and any help would be appreciated. Thanks!

Upvotes: 4

Views: 6386

Answers (2)

Chitranshu Asthana
Chitranshu Asthana

Reputation: 1089

I havn't tried it myself. but looks like it should work. Kindly try it out.

m_audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
m_audioManager.setMode(AudioManager.MODE_IN_CALL);

Upvotes: -1

Mahendra Liya
Mahendra Liya

Reputation: 13218

I would personally not suggest you to STREAM_VOICE_CALL as it is meant to be recommended to use it for Voice calls as compared to media playback. Using this may prevent you from using features exposed by Android for media playback.

Having said this & taking into consideration your use-case, I think you need to look for changing 'call volume' level as compared to 'media volume' level.

Have a look at the MediaPlaybackService.java as used in the stock Music Player app and try to customize it as per your needs.

Upvotes: 3

Related Questions