We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
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.
void setup() {
}//setup
void draw () {
}//draw
void mousePressed() {
}//mousePressed
void stop() {
}//stop
where i can find the library android media player??
@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 :-)