我正在尝试为学校的 java 项目制作媒体播放器,它说 javax.media 的导入无法解决,我们将不胜感激。下面是我使用的代码。就像我说的,如果有人可以帮助我弄清楚,将不胜感激。
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");
}
}