In many ways but one of them is this:
import javax.media.*;
import java.io.*;
public class PlayMP3Thread
extends Thread
{
private URL url;
public PlayMP3Thread(File mp3)
{
this.url = mp3.toURL();
}
public void run()
{
try
{
MediaLocator ml = new MediaLocator(url);
Player player = Manager.createPlayer(ml);
player.addControllerListener(
new ControllerListener()
{
public void controllerUpdate(ControllerEvent event)
{
if (event instanceof EndOfMediaEvent)
{
player.stop();
player.close();
}
}
}
);
player.realize();
player.start();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}