Preparing two MediaPlayers in the same activity
<p>I would like to prepare two MediaPlayers in the same activity. I buffer mp3 from net and becouse it takes some time, my idea to speed it up was: when first sample is playing, the second is preparing. </p>

<p>Unfortunately I can't make it work. That is method for buffering:</p>

<pre><code>    private void getMusic(MediaPlayer player, String url) {

    player = new MediaPlayer();
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        player.setDataSource(url);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    player.setOnPreparedListener(this);
    player.prepareAsync();          
}
</code></pre>

<p>And this is onPrepared method.</p>

<pre><code>    @Override
public void onPrepared(MediaPlayer player) {

    preparedEnd=true;
    prepareState++;
    player.start();
    if(prepareState==1)
        getMusic(player2, "some_url");
}
</code></pre>

<p>I thought that if player would be prepared, I could use prepareAsync() again. I tried some others ideas, but no one helped. The problem is with prepareAsync(), becouse when I used prepare() there weren't any problems. </p>

<p>That's my errors:</p>

<pre><code>05-23 01:35:22.848: E/MediaPlayer(29894): prepareAsync called in state 1
05-23 01:35:22.858: D/AndroidRuntime(29894): Shutting down VM
05-23 01:35:22.858: W/dalvikvm(29894): threadid=1: thread exiting with uncaught exception (group=0x40ab0228)
05-23 01:35:22.868: E/AndroidRuntime(29894): FATAL EXCEPTION: main
05-23 01:35:22.868: E/AndroidRuntime(29894): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crivline.musicGame/com.crivline.musicGame.NewGame}: java.lang.IllegalStateException
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.os.Looper.loop(Looper.java:156)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.ActivityThread.main(ActivityThread.java:4977)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at java.lang.reflect.Method.invokeNative(Native Method)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at java.lang.reflect.Method.invoke(Method.java:511)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at dalvik.system.NativeStart.main(Native Method)
05-23 01:35:22.868: E/AndroidRuntime(29894): Caused by: java.lang.IllegalStateException
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.media.MediaPlayer._prepareAsync(Native Method)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.media.MediaPlayer.prepareAsync(MediaPlayer.java:1357)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.crivline.musicGame.NewGame.getMusic(NewGame.java:460)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.crivline.musicGame.NewGame.selectPlayer(NewGame.java:427)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.crivline.musicGame.NewGame.prepareMediaPlayer(NewGame.java:413)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.crivline.musicGame.NewGame.getData(NewGame.java:270)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at com.crivline.musicGame.NewGame.onCreate(NewGame.java:125)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.Activity.performCreate(Activity.java:4538)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
05-23 01:35:22.868: E/AndroidRuntime(29894):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
05-23 01:35:22.868: E/AndroidRuntime(29894):    ... 11 more
</code></pre>

<p>THANKS A LOT FOR HELP IN ADVANCE!</p>
