Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Thelma Murray   on Aug 31 In Java Category.

  
Question Answered By: Wilfred Young   on Aug 31

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();
}
}

}

Share: