TBD.my

Full Version: java background music library
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
import javax.media.*;
import java.net.URL;
  
public class Mp3PlayerDemo extends Thread {
  
   private String filename;
   Player player;
  
   public Mp3PlayerDemo(String mp3Filename) {
      this.filename = mp3Filename;
   }
  
   public void run() {
      try {
         URL url = this.getClass().getClassLoader().getResource(filename);
         MediaLocator locator = new MediaLocator(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();
   }
}

java.lang.NullPointerException
at javax.media.MediaLocator.<init>(MediaLocator.java:37)
at Mp3PlayerDemo.run(Mp3PlayerDemo.java:16)



aku xdak library ke apa yg salah ? :3