package racemaster;
import javax.media.*;
//To run this class, JMF and its MP3 plug-in must be installed in the PC
public class SoundFile {
String filename;
public SoundFile(String filename) {
this.filename = filename;
}
public void play() throws Exception {
MediaLocator mrl = new MediaLocator(getClass().getResource(filename));
Player player = Manager.createPlayer(mrl);
player.start();
}
public String getFileName(){
return filename;
}
}
So that the mp3 (and even wav) could be called declaring a SoundFile variable with a String representing the file name and using its play() method.
I then ran my program, only to find that when the sound is attempted to be played, I get
javax.media.NoPlayerException: Cannot find a Player for :jar:file:/F:/RaceMaster/src/racemaster/Music.jar!/readysetgo.mp3
Is it normal for the IDE (I use NetBeans) to read the JAR address as .jar! ? Anyways the error points to the line
MediaLocator mrl = new MediaLocator(getClass().getResource(filename));
So after searching some more I tried adding the .getClassLoader() method to see if it could play, but instead of getting the NoPlayerException I get a NullPointerException, yet I don't know which variable is null, since the filename variable is passed correctly. I've seen another tutorial where they recommend to add a "file:///" to the MediaLocator parameter, so I change it to this:
MediaLocator mrl = new MediaLocator("file:///" + getClass().getClassLoader().getResource(filename).getFile());
And get a NullPointerException. I tried like this:
MediaLocator mrl = new MediaLocator("file:///" + getClass().getClassLoader().getResource(filename));
And get
java.io.IOException: File Not Foundfor the SoundFile to be played, and
javax.media.NoPlayerException: Error instantiating class: com.sun.media.protocol.file.DataSource : java.io.IOException: File Not Found
so I'm really not sure how to get around this. Please let me know if anyone knows anything, I think I'm pretty close to get it all done =D Any help or thoughts are very welcome and appreciated! (sorry if it was too long, but I wanted to explain everything to avoid any confusion)

New Topic/Question
Reply




MultiQuote




|