Andriod mediaPlayer prepare() failed status=0x1

edited August 2014 in Android Mode

I am trying to test the Android's mediaplayer to play sound in a my processing app in Android mode. It keeps failing at prepare. Here is the code.

It fails at player.prepare() and the failure occurs with IOException. I am at a lost. Really appreciate any help.

// libraries
import android.media.MediaPlayer;

// audio variables
MediaPlayer player;

void setup() {

    size (100, 100);

    player = new MediaPlayer();

    try {
        player.setDataSource("wall.wav");
        player.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    }       

}//setup

void draw () {

}//draw

void mousePressed() {

    if (player.isPlaying()) {//do nothing, is playing
    } else {
        player.seekTo(0); //rewind to beginning
        player.start();
    }

}//mousePressed

void stop() {

    // releases any resource attached with the MediaPlayer object
    player.release();
    super.stop();

}//stop

Answers

  • edited August 2014 Answer ✓

    Hi everyone, I found the solution. I needed to get to the sound file via the android Assets. I found the needed code under a discussion title "Sound Library". Here is the working code. "wall.wav" is just a bell sound located in the data folder.

    // libraries
    import android.media.*;
    import android.content.res.*;
    
    // audio variables
    MediaPlayer player;
    AssetManager assets;
    AssetFileDescriptor fd;
    

    void setup() {

    size (100, 100);
    
    player = new MediaPlayer();
    assets = this.getAssets();
    
    try {
      fd = assets.openFd("wall.wav");
      player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
      player.prepare();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    }    
    

    }//setup

    void draw () {

    }//draw

    void mousePressed() {

    if (player.isPlaying()) {//do nothing, is playing
    } else {
      player.seekTo(0); //rewind to beginning
      player.start();
    }
    

    }//mousePressed

    void stop() {

    // releases any resource attached with the MediaPlayer object
    player.release();
    super.stop();
    

    }//stop

  • where i can find the library android media player??

  • edited August 2014

    @marioporty88: Android's MediaPlayer is part of the Android API, so you do not need any additional libraries.

  • oh..thanks calsign

  • Thanks BigfootSue, now I can play mp3 file on my Galaxy III :-)

Sign In or Register to comment.