Android music player prepare method failed
<p>I have been trying to play an MP3 file. It just won't work.</p>

<p>I did manage to play it and add all sorts of functionalities to it with the very same/similar code a few days ago. Just tried to make it all over again and now these errors...</p>

<p>Can someone point out the error also why does this happen.</p>

<p>Just to clarify I used different formats of URI, none of them work. Thought maybe its the prepare method. </p>

<pre><code>package com.player.phoneagent.gui;


import java.io.IOException;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;


public class AndroidClientActivity extends Activity {
    /** Called when the activity is first created. */

    private MediaPlayer mp;
    String path = "android.resource://com.player.phoneagent/raw/test";

    ImageButton btn_prev;
    ImageButton btn_play;
    ImageButton btn_pause;
    ImageButton btn_next;


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btn_prev = (ImageButton) findViewById(R.id.ImageButton01);
        btn_pause = (ImageButton) findViewById(R.id.ImageButton02);
        btn_play = (ImageButton) findViewById(R.id.ImageButton03);
        btn_next = (ImageButton) findViewById(R.id.ImageButton04);

        mp = new MediaPlayer();
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);


        btn_play.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try {
                    mp.setDataSource(path); 

                } catch (IllegalArgumentException e) {

                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    mp.prepare();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                mp.start();

            }
        });

    }

}






08-01 07:06:00.142: W/KeyCharacterMap(407): No keyboard for id 0
    08-01 07:06:00.142: W/KeyCharacterMap(407): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
    08-01 07:06:05.821: D/dalvikvm(407): GC_EXPLICIT freed 21K, 53% free 2568K/5379K, external 3207K/3962K, paused 55ms
    08-01 07:06:20.311: D/dalvikvm(444): GC_EXTERNAL_ALLOC freed 52K, 53% free 2552K/5379K, external 1969K/2137K, paused 58ms
    08-01 07:06:43.171: E/MediaPlayer(444): error (1, -2147483648)
    08-01 07:06:43.171: W/System.err(444): java.io.IOException: Prepare failed.: status=0x1
    08-01 07:06:43.171: W/System.err(444):  at android.media.MediaPlayer.prepare(Native Method)
    08-01 07:06:43.171: W/System.err(444):  at com.player.phoneagent.gui.AndroidClientActivity$1.onClick(AndroidClientActivity.java:60)
    08-01 07:06:43.171: W/System.err(444):  at android.view.View.performClick(View.java:2485)
    08-01 07:06:43.171: W/System.err(444):  at android.view.View$PerformClick.run(View.java:9080)
    08-01 07:06:43.181: W/System.err(444):  at android.os.Handler.handleCallback(Handler.java:587)
    08-01 07:06:43.181: W/System.err(444):  at android.os.Handler.dispatchMessage(Handler.java:92)
    08-01 07:06:43.181: W/System.err(444):  at android.os.Looper.loop(Looper.java:123)
    08-01 07:06:43.181: W/System.err(444):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-01 07:06:43.181: W/System.err(444):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-01 07:06:43.181: W/System.err(444):  at java.lang.reflect.Method.invoke(Method.java:507)
    08-01 07:06:43.181: W/System.err(444):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    08-01 07:06:43.181: W/System.err(444):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-01 07:06:43.181: W/System.err(444):  at dalvik.system.NativeStart.main(Native Method)
    08-01 07:06:43.181: E/MediaPlayer(444): start called in state 0
    08-01 07:06:43.181: E/MediaPlayer(444): error (-38, 0)
    08-01 07:06:43.181: E/MediaPlayer(444): Error (-38,0)
</code></pre>
