Android MediaPlayer throwing “Prepare failed.: status=0x1” on 2.1, works on 2.2

This is my solution: MediaPlayer mediaPlayer = new MediaPlayer(); FileInputStream fis = null; try { File directory = new File(“android.resource://com.example.myapp/raw/”); fis = new FileInputStream(directory); mediaPlayer.setDataSource(fis.getFD()); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.prepare(); } finally { if (fis != null) { try { fis.close(); } catch (IOException ignore) { } } }

Stopping & starting music on incoming calls

There are a few things you can do: First of all, you can listen for changes in the call state using a PhoneStateListener. You can register the listener in the TelephonyManager: PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { //Incoming call: Pause music } … Read more

Android MediaPlayer Stop and Play

You should use only one mediaplayer object public class PlayaudioActivity extends Activity { private MediaPlayer mp; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b = (Button) findViewById(R.id.button1); Button b2 = (Button) findViewById(R.id.button2); final TextView t = (TextView) findViewById(R.id.textView1); b.setOnClickListener(new View.OnClickListener() { @Override public void … Read more

Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one

Shoutcast mp3 streaming from Android 2.2 onwards is supported natively . Below 2.2 the Android OS cannot play shoutcast streams natively without using a proxy on the stream end or a stream proxy class on the device to capture the stream and pass it to the audioplayer just like NPR does. audio/aacp streaming is not … Read more

Android MediaPlayer error (1, -2147483648)

Just to clarify something for anyone reading this question based on the title. When looking at the error value (1, -2147483648), the ‘1’ value corresponds to the constant in MediaPlayer.MEDIA_ERROR_UNKNOWN. -2147483648 corresponds to hexadecimal 0x80000000 which is defined as UNKNOWN_ERROR in frameworks/native/include/utils/Errors.h This shows that the error’s source is hard to pin down as it … Read more