MediaPlayer start->stop->start for MIDI files

0

I am seeing a problem with MediaPlayer, trying to do the next sequence start()->stop()->start() for MIDI files gives me an error.

By looking at the MediaPlayer state diagram, the sequence should work with the next code:

void experiment() throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
    Context context = this;
    int resid = R.raw.teddybear;
    String packageName = getResources().getResourcePackageName(resid);
    Uri uri = Uri.parse("android.resource://" + packageName + "/"  + resid);
    MediaPlayer mp = new MediaPlayer();
    mp.setDataSource(context, uri);
    mp.prepare();
    mp.start();
    mp.stop();
    mp.prepare();
    mp.start();
}

Here is the error is get from the call to the second prepare:

java.io.IOException: Prepare failed.: status=0xFFFFFFFD

This problem does not exist for other sound files.

Is anyone experiencing this also? Am i doing something wrong?

I am not trying to find walk-around - got plenty :)

Things tried:

  • removing the stop and stop&prepare&start allows this stream to be played.

  • I've heard that the MediaPlayer is not immediately get updated for its state, so i added sleeps between the methods - still same issue.

  • Changing the file type solved the issue.

  • trying several MIDI file yield the same result.

  • registering an OnError also did not worked - he was not called

Can it be that this is a bug? Thanks.

android
android-mediaplayer
asked on Stack Overflow Apr 20, 2013 by talel

1 Answer

0
  1. As you said:Changing the file type solved the issue.
  2. Try SoundPool
answered on Stack Overflow May 31, 2013 by wangxt

User contributions licensed under CC BY-SA 3.0