Set app volume stream

159 views
Skip to first unread message

Kallikratidas

unread,
Oct 28, 2020, 4:20:46 AM10/28/20
to DroidScript
How can you set the default volume stream for your app? (eg. for the stream "music", when user presses the volume up or down buttons on his device, should only change the volume of the defined stream "music").

I hope my question was clear and has a solution. I am working on a music app and this feature really can't be omited!

Regards!

Alan Hendry

unread,
Oct 28, 2020, 6:21:39 AM10/28/20
to DroidScript
HI,
The beta version allows SetOnBroadcast to receive the presses of the physical volume up and volume down.
I would presume that the Broadcast still goes to all the other apps, like Phone, so their volume may also change.
(Typing this in here, there may be typos)
app.SetOnBroadcast(rb,"android.media.VOLUME_CHANGED_ACTION") ;
function rb(type,msg) {
 alert(JSON.stringify(type));
 alert(JSON.stringify(msg));
Regards, ah

Kallikratidas

unread,
Oct 28, 2020, 8:10:32 AM10/28/20
to DroidScript
Dear Hendry, thanks for your answer.
However, my problem is not how to listen to volume changes. This can be achieved in many other ways, such as creating an interval and getting volume data, or by using app.SetOnKey(); My question is how to define the default volume stream that the user will be using when being in the app. For example, when you make a call on your phone and raise the volume either up or down, the volume the apply changes on is the voice call stream and not the music or any other.  In the music app that I am working on, I want the default volume stream to be set to "music". I know that by creating a media player and playing a sound, this change is being done by default (when you use an audio player in your app and the track starts playing, then the volume that changes when you raise the volume up or down the music stream and not the ringtone). However, I want this to be done from the very beginning of the app,  not just when the sound starts playing, just in every single music app.

I hope I was more clear now and this issue can be managed.

Regards!

Alan Hendry

unread,
Nov 2, 2020, 6:34:37 AM11/2/20
to DroidScript
Hi,
Still not sure what you're trying to do.
The methods I know of communicating between apps seem to be QueryContent and Intent/Broadcast.
In DS QueryContent is a premium function (I'm not premium) but I think you want to change other apps settings, not just read them.
There's an intent that can open the Settings  > Sound screen, so the user could change ring/notiifcation/media/alarm themselves.
null,null,"android.settings.SOUND_SETTINGS"
If you need to set the volume absolutely at the start of the media, 
you can CreateMediaPlayer, then SetVolume (left and right), then SetFile.
If you have a control to set volume then you can save the settings and load them the next time the user starts the app.
Regards, ah

Cemal

unread,
Nov 3, 2020, 5:38:46 AM11/3/20
to DroidScript
Maybe it's help you:
app.SetVolume( "Music", app.GetVolume("Music"), "ShowUI" );
for more information look: Docs/Reference/Sounds/Set Volume
Reply all
Reply to author
Forward
0 new messages