title: controlling volume in MediaPlayer
body: <p>I'm playing audio (narration) in an audiobook.  The audio files are in .ogg format, between 10 and 15 seconds long each.</p>
  
  <p>Edit to add: I'm using Android 2.2, API 8, and I have this in my Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /&gt;
  </code></pre>
  
  <p>I've got <a href="https://stackoverflow.com/questions/2539264/volume-control-in-android-application/2539402#2539402">setVolumeControlStream(AudioManager.STREAM_MUSIC);</a> in my onCreate() method.</p>
  
  <p>My sounds are being played via code similar to this:</p>
  
  <pre><code>mp = MediaPlayer.create(mContext, resource);
  mp.setOnCompletionListener(this);
  mp.seekTo(0);
  mp.setLooping(looping);
  if(isSoundEnabled())
  {
      mp.setVolume(1, 1);
  }
  else
  {
      // I still need sounds to call their onComplete listeners to drive action
      mp.setVolume(0,0);
  }
  nowPlaying = true;
  mp.start();
  </code></pre>
  
  <p>But, despite more assurances (33 and counting!) that one simply needs <a href="https://stackoverflow.com/questions/628659/how-can-i-manage-audio-volumes-sanely-in-my-android-app/674207#674207">setVolumeControlStream(AudioManager.STREAM_MUSIC);</a> in onCreate(), my sounds don't change in volume when I press the volume keys on my device (Motorola Xoom).</p>
  
  <p>To verify my volume keys were doing <em>something</em>, I overrode <code>onKeyDown</code>:</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      boolean result = true;
      if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
      {
          DebugLog.d(TAG, "volume up");
      }
      else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
      {
          DebugLog.d(TAG, "volume down");
      }
  }
  </code></pre>
  
  <p>and confirmed via LogCat that I'm pressing the correct volume keys:</p>
  
  <pre><code>07-19 12:16:31.440: DEBUG/BookReader(17830): volume down; thread 1
  07-19 12:16:31.710: DEBUG/BookReader(17830): volume down; thread 1
  07-19 12:16:31.980: DEBUG/BookReader(17830): volume down; thread 1
  07-19 12:16:32.440: DEBUG/BookReader(17830): volume up; thread 1
  07-19 12:16:32.820: DEBUG/BookReader(17830): volume up; thread 1
  </code></pre>
  
  <p>Though the following link is about <code>SoundPool</code>, should I be <a href="https://stackoverflow.com/q/4180960/194309">calculating stream volume</a> instead of using <code>mp.setVolume(1, 1);</code> in my first code sample above?</p>