Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
java background music library
09-12-2012, 05:21 PM,
Post: #1
java background music library
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
[Image: Captu3re.jpg]
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Soalan Java darknite 10 848 27-11-2013, 01:47 PM
Last Post: darknite
  soalan java. hard3 4 955 10-05-2013, 10:33 PM
Last Post: JejakaPemalu
  [help] inputfile java please click me to know more Timon 0 402 14-04-2013, 10:02 PM
Last Post: Timon
  [problem]with java tcp client and server chat pron3t 1 575 26-02-2013, 01:21 PM
Last Post: muhaznar
  java API Timon 3 862 09-12-2012, 09:58 PM
Last Post: lamki
  JAVA Layout... mana 1 feveret :P 127001 7 1,719 03-12-2012, 10:32 AM
Last Post: Wushipher
  Java | MS Excell 127001 5 1,063 29-07-2012, 12:41 AM
Last Post: lamki
  Tutorial: Menghubungkan SQLite Dengan Java s3m00t 4 1,333 25-07-2012, 02:40 AM
Last Post: s3m00t
  [java prob]guna user input dan methode erroe indintifier pron3t 2 679 22-04-2012, 07:56 PM
Last Post: pron3t
  [Tut]Java Array Name Ujang 2 746 19-04-2012, 03:07 PM
Last Post: pron3t

Forum Jump: