Reputation: 13
I am trying to make a media player for a project in java for school and it says that the imports for javax.media cannot be resolved and any help would be appreciated. Below is the code iI have used. Like I said if anybody can help me to figure it out it would be greatly appreciated.
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;
public class MediaPlayer<Player> extends JPanel
{
private Player mediaPlayer;
private Component Video;
private Component controls;
public MediaPlayer (URL mediaURL) throws IOException
{
setLayout(new BorderLayout() );
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try
{
Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
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");
}
}
Upvotes: 1
Views: 7125
Reputation: 12123
The Java Media Framework is an optional package. I believe you have to download it separately.
The Java Media Framework API (JMF) enables audio, video and other time-based media to be added to applications and applets built on Java technology. This optional package, which can capture, playback, stream, and transcode multiple media formats, extends the Java 2 Platform, Standard Edition (J2SE) for multimedia developers by providing a powerful toolkit to develop scalable, cross-platform technology. (source)
After downloading it, you need to add it to your classpath.
Upvotes: 1