我可以使用 Java 媒体框架播放 .mpg 格式的视频。但我无法播放所有格式的视频。当我想播放.AVI格式的视频时,视频在播放,但没有声音。如何播放FLV、mp4、avi等其他格式?
public class MediaPanel extends JPanel
{
public Player mediaPlayer;
public Component video;
public Component controls;
public MediaPanel(URL mediaURl)
{
setLayout(new BorderLayout());
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try
{
//Player
// this. mediaPlayer.stop();
//this.mediaPlayer.close();
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");
}
catch(CannotRealizeException cannotRealizeException)
{
System.err.println("Could not");
}
catch(IOException iOException)
{
System.err.println("Error");
}
}}