Thursday, June 30, 2011

[android-developers] MediaPlayer and IllegalStateException

I've try to copy a very small and easy sample of using MediaPlayer
(for example in http://developer.android.com/guide/topics/media/index.html)
but I dont know the reason I get an IllegalStateException.

Code can be sumarized as:
MediaPlayer mp = MediaPlayer.create(myclass_name_here.this,
R.raw.clip);
boolean error=true;
try {
mp.prepare();
error=false;
} catch (IOException ioe) {
Log.w("Player","Error: "+ioe.getMessage());
}
if(!error) {
mp.start();
}

I have a raw directory under res, it has the "clip.mp3" file, I've
check the file is ok, so why I get a java.lang.IllegalStateException
in mp.prepare(); I've tested in 2 different android phones.

Best regards.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment