-
Problem with JMF
Hi,
I'm trying to play a song with JMF, the song location is in my computer.
I'm getting an exception of CannotRealizeException.
I'm king of new programmer with JMF, here is my code :
Code:
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class SimpleAudioPlayer {
private Player audioPLayer;
public SimpleAudioPlayer(URL url) throws IOException, NoPlayerException, CannotRealizeException {
audioPLayer = Manager.createRealizedPlayer(url);
}
public SimpleAudioPlayer(File file) throws IOException, NoPlayerException, CannotRealizeException {
this(file.toURI().toURL());
}
public void play() {
audioPLayer.start();
}
public void stop() {
audioPLayer.stop();
audioPLayer.close();
}
public static void main(String[] args) {
try {
File file = new File("C://Users//Or//Downloads//Songs//a.mp3") ;
SimpleAudioPlayer simpleAudioPlayer = null;
simpleAudioPlayer = new SimpleAudioPlayer(file);
simpleAudioPlayer.play();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (NoPlayerException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (CannotRealizeException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
I have a song with a.mp3 name at this location, and i dont know what is the reason i'm gettting this exception.
Hope that someone can help me..
Thanks,
Or.
-
Re: Problem with JMF
Have you installed the MP3 Plugin?
db
-
Re: Problem with JMF
Hi and thank you for your answer.
I just installed the plugin, and still get the same exception.
Thanks,
Or.
-
Re: Problem with JMF
This is the error message :
"Failed to realize: com.sun.media.PlaybackEngine@2beee406
Error: Unable to realize com.sun.media.PlaybackEngine@2beee406
javax.media.CannotRealizeException"
It happens when i'm trying to use Manager.createRealizedPlayer function with audio or video.
-
Re: Problem with JMF
Have you tried the same code with another media format, say .SND or .AU?
db
-
Re: Problem with JMF
You could always use EasyOgg, and use the media format .ogg. It may scale down the quality but the compression is amazing. MP3s support in the native JRE has not been support for quite a while. That is, the JMF, has not been updated. I tried using it before and ran into a bunch of problems. Pretty much the same situations that you are in.
When you do EasyOgg, you have to make sure the Audio Codec is "vorbis" to get it to work.