How to increase and decrease the volume programmatically in Android
<p>I created a music player app and I want to set the volume up/down programmatically. I want to implement two <code>Button</code>s to increase/decrease the volume and set to the media player.</p>
<p><strong>Activity</strong>:</p>
<pre><code>control = (ImageView) findViewById(R.id.control);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
control.setOnClickListener(pausePlay);
control.setBackgroundResource(R.drawable.pause);
control id is my play and pause button :
{
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub

        if (playPause) {
            control.setBackgroundResource(R.drawable.play);
            if (mediaPlayer.isPlaying())
                mediaPlayer.pause();
            media.stop();
            intialStage = false;
            playPause = false;

        } else {
            control.setBackgroundResource(R.drawable.pause);
            if (intialStage) {
                new Player()
                        .execute(&quot;http://streaming.shoutcast.com/MUKILFMRADIO&quot;);
            } else {
                if (!mediaPlayer.isPlaying())
                    mediaPlayer.start();
            }
            playPause = true;
        }
}
</code></pre>
<p><strong>Layout</strong>:</p>
<pre class="lang-xml prettyprint-override"><code>&lt;LinearLayout
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:orientation=&quot;horizontal&quot;
    android:gravity=&quot;center&quot;&gt;
    &lt;ImageView
        android:layout_width=&quot;40dp&quot;
        android:layout_height=&quot;40dp&quot;
        android:id=&quot;@+id/control1&quot;
        android:layout_margin=&quot;10dp&quot;
        android:layout_gravity=&quot;center&quot;
        android:background=&quot;@drawable/decrement&quot;
        android:layout_above=&quot;@+id/latestAddedSongs&quot;
        android:layout_alignEnd=&quot;@+id/musicArtistName&quot; /&gt;
    &lt;ImageView
        android:layout_width=&quot;70dp&quot;
        android:layout_height=&quot;70dp&quot;
        android:id=&quot;@+id/control&quot;
        android:layout_margin=&quot;10dp&quot;
        android:layout_gravity=&quot;center&quot;
        android:background=&quot;@drawable/play&quot;
        android:layout_above=&quot;@+id/latestAddedSongs&quot;
        android:layout_alignEnd=&quot;@+id/musicArtistName&quot; /&gt;
    &lt;ImageView
        android:layout_width=&quot;40dp&quot;
        android:layout_height=&quot;40dp&quot;
        android:id=&quot;@+id/control2&quot;
        android:layout_margin=&quot;10dp&quot;
        android:layout_gravity=&quot;center&quot;
        android:background=&quot;@drawable/increment&quot;
        android:layout_above=&quot;@+id/latestAddedSongs&quot;
        android:layout_alignEnd=&quot;@+id/musicArtistName&quot; /&gt;
&lt;/LinearLayout&gt;
</code></pre>