title: Android - How to change sound output while playing sound?
body: <p>I have an app that plays a list of soundtracks. It works great, however changing the sound output to internal speakers or vice versa, has no effect. It stops the current one, and then plays the next on the new mode.</p>
  
  <p>I've read in android documentation of <a href="http://developer.android.com/reference/android/media/MediaPlayer.html#prepareAsync()" rel="nofollow">MediaPlayer</a> that I can't change the sound output using setAudioStreamType() method. So this is the problem, but can't find a solution!</p>
  
  <p>Here's the code for the toggle when the track is playing:</p>
  
  <pre><code>        if (this.audioManager.isSpeakerphoneOn() || this.getCurrent() == 1) {
              this.audioManager.setMode(AudioManager.MODE_IN_CALL);
              this.audioManager.setSpeakerphoneOn(false);
              this.mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
          } else if (this.getCurrent() != 0) {
              this.audioManager.setMode(AudioManager.MODE_NORMAL);
              this.audioManager.setSpeakerphoneOn(true);
              this.mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
          }
  </code></pre>
  
  <p>Thanks in advance!</p>