我正在尝试使用javax.mediaplayer播放.avi格式的视频,这是方法
void open() {
// create a file chooser
JFileChooser fileChooser = new JFileChooser();
// show open file dialog
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) // user chose a file
{
URL mediaURL = null;
try {
// get the file as URL
mediaURL = fileChooser.getSelectedFile().toURL();
} // end try
catch (MalformedURLException malformedURLException) {
System.err.println("Could not create URL for the file");
} // end catch
if (mediaURL != null) // only display if there is a valid URL
{
JFrame mediaTest = new JFrame("Media Tester");
mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MediaPlayer mediaPanel = new MediaPlayer();
mediaPanel.setMediaLocator(new MediaLocator(mediaURL));
mediaTest.add(mediaPanel);
mediaTest.setSize(300, 300);
mediaTest.setVisible(true);
} // end inner if
} // end outer if
}
问题是每当我运行时,它运行成功并且jframe弹出但是空了,里面没有视频,,,任何帮助?