How to control volume to app media on Android

Asked

Viewed 1,464 times

4

I’m like a doubt on how to control the volume of the app’s media.

I’m using this method:

Button button1;
MediaPlyer mp;
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    mp = MediaPlayer.create(Teste.this, R.raw.som);
    mp.start();
}

});

I wanted to decrease or increase the volume on the device, change the app and not mobile.

3 answers

3

  • blz, but I wanted to control the volume of the application on the physical device, because when you press to increase the volume it increases the device and not the app, to be able to increase the volume of the application and only when it is active (when you call the sound ), but it does not give a lot of time, because they are very short sounds.

2

You can use the Audiomanager.

Example of use:

AudioManager audio = (AudioManager)  
        getApplicationContext().getSystemService(Context.AUDIO_SERVICE);

audio.setStreamVolume(AudioManager.STREAM_MUSIC, VALOR, 0); // Valor: 0~15

1


Add in(s) Activity that you want to change the media volume instead of the bell the method below:

@Override
    protected void onStart() {
        super.onStart();
        setVolumeControlStream (AudioManager.STREAM_MUSIC);
    }

The method onStart() refers to when the application starts.

There is more information on these links below:

link 1

link 2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.