arahman22

MP3PlayerDemo

Jun 19th, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import javax.media.*;
  2. import java.net.URL;
  3.    
  4. public class MP3PlayerDemo extends Thread {
  5.    
  6.    public String filename;
  7.    Player player;
  8.    
  9.    public MP3PlayerDemo(String mp3Filename) {
  10.       this.filename = mp3Filename;
  11.       System.out.println(filename);
  12.    }
  13.    
  14.    public void run() {
  15.       try {
  16.          System.out.println("x " + filename);
  17.          URL url = this.getClass().getClassLoader().getResource(filename);
  18.          System.out.println("2 " + url);
  19.          MediaLocator locator = new MediaLocator(url);
  20.          System.out.println(url);
  21.          player = Manager.createPlayer(locator);
  22.          player.addControllerListener(new ControllerListener() {
  23.             public void controllerUpdate(ControllerEvent event) {
  24.                if (event instanceof EndOfMediaEvent) {
  25.                   player.stop();
  26.                   player.close();
  27.                }
  28.             }
  29.          });
  30.          player.realize();
  31.          player.start();
  32.       } catch (Exception e) {
  33.          e.printStackTrace();
  34.       }
  35.    }
  36.    
  37.    public static void main(String[] args) {
  38.       new MP3PlayerDemo("song.mp3").start();
  39.    }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment