I'm working on a project for a programming class, and I want to add a video file. I've tried using JMF, except when I try to play a video (using one of the formats listed on the Java website), it gives me the error:
Unable to handle format: XVID, 320x213, FrameRate=29.9, Length=204480 0 extra bytes
Unable to handle format: mpeglayer3, 22050.0 Hz, 0-bit, Stereo, Unsigned, 8000.0 framerate,FrameSize=4608 bits
Failed to realize: com.sun.media.PlaybackEngine@39b27b
Error: Unable to realize com.sun.media.PlaybackEngine@39b27b
Could not realize media player
This is the code I use to test the player:
public MediaPanel(String path) {
try {
videoPath = new File(path).toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
setLayout(new BorderLayout());
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try {
Player mediaPlayer = Manager.createRealizedPlayer(videoPath);
Component video = mediaPlayer.getVisualComponent();
Component controls = mediaPlayer.getControlPanelComponent();
if (video != null)
add(video, BorderLayout.CENTER);
if (controls != null)
add(controls, BorderLayout.SOUTH);
mediaPlayer.start();
} catch (NoPlayerException NoPlayerException) {
System.err.println("No media player found");
} catch (CannotRealizeException CannotRealizeException) {
System.err.println("Could not realize media player");
} catch (IOException IOException) {
System.err.println("Error reading from the source");
}
}
MediaPanel player = new MediaPanel("intro.avi");
I assume my two options are to make a video with the exact specifications listed on the Java website (because apparently just the file extension isn't enough), or use another method to display video.
How can I fix this? Do I need to make a video exactly as the specifications note (see link at bottom)?
NOTE: The class I'm in uses and older version of java that DOESN'T contain javaFX. Please don't recommend this unless there is a way I can add it without having the school reinstall a newer version of Java.