Hi guys,
I'm trying to learn how to play sounds (MP3's) on an app. I have it working but I can only play one file and then it does not play anything else.
I created a class that does everything:
package SoundMaker;
import javax.microedition.media.*;
import java.io.*;
public class PlayXYZ implements Runnable{
public void run()
{
try
{
InputStream in = getClass().getResourceAsStream("/XYZ.mp3");
Player player = Manager.createPlayer(in, "audio/mpeg");
player.start();
}
catch (Exception e) {
//showException(e);
return;
}
}
}
I am using the following code to initialize an instance of the class, a new thread and start it:
PlayXYZ p = new PlayXYZ();
Thread myThread = new Thread( p );
myThread.start();
I'm using a new thread because I though it may be possible to play multiple sounds with them, but it may not be possible...
Alright. The problem is when I create another instance of my class and a new thread. It does not play anything. Only the first sound plays...
For now, I dont care if it does not play multiple sounds, but I would like to be able to play a sound after the other. Or stop a sound when another sound starts, just like KBPiano.
Any help would be greatly appreciated.