Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.media.*;
- import java.net.URL;
- public class MP3PlayerDemo extends Thread {
- public String filename;
- Player player;
- public MP3PlayerDemo(String mp3Filename) {
- this.filename = mp3Filename;
- System.out.println(filename);
- }
- public void run() {
- try {
- System.out.println("x " + filename);
- URL url = this.getClass().getClassLoader().getResource(filename);
- System.out.println("2 " + url);
- MediaLocator locator = new MediaLocator(url);
- System.out.println(url);
- player = Manager.createPlayer(locator);
- 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();
- }
- }
- public static void main(String[] args) {
- new MP3PlayerDemo("song.mp3").start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment