How to control the volume of the app media on Android

4

I'm having a question about how to control the media volume of the app.

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, I would change the app and not the phone.

    
asked by anonymous 01.02.2015 / 12:35

3 answers

1

Add to Activity (s) that you want the media volume to be changed instead of the buzzer method below:

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

The onStart() method references when the application starts.

There is more information on these links below:

/ a>

link 2

    
04.02.2017 / 20:53
3

To control the volume of your application in MediaPlayer, you can use the "setVolume" method

// Volume baixo em ambos os lados (Esquerdo e direito) mp.setVolume(0,0)

To learn more about this method, visit: link , float)

    
01.02.2015 / 13:17
2

You can use the AudioManager .

Example usage:

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

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