Buduję prosty program do odtwarzania filmów w java.
Znalazłem taki przykład i coś z nim jest nie tak, czy mógłby mi ktoś podpowiedzieć gdzie jest błąd?
package SimpleVideoPlayerWithJava;
import java.awt.BorderLayout;
import java.awt.Component;
import java.net.MalformedURLException;
import java.net.URL;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
public class SimpleVideoPlayerWithJava extends javax.swing.JPanel {
public SimpleVideoPlayerWithJava(URL mediauUrl) {
initComponents();
setLayout(new BorderLayout());
try {
Player mediaPlayer = Manager.createRealizedPlayer(new MediaLocator(mediauUrl));
Component video = mediaPlayer.getVisualComponent();
Component control = mediaPlayer.getControlPanelComponent();
if (video != null) {
add(video, BorderLayout.CENTER); // place the video component in the panel
}
add(control, BorderLayout.SOUTH); // place the control in panel
mediaPlayer.start();
} catch (Exception e) {
}
}
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getTopLevelAncestor());
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 720, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 480, Short.MAX_VALUE)
);
}
public static void main(String[] args) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(null);
URL mediaUrl = null;
try {
mediaUrl = fileChooser.getSelectedFile().toURI().toURL();
} catch (MalformedURLException ex) {
System.out.println(ex);
}
JFrame mediaTest = new JFrame("Movie Player");
mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SimpleVideoPlayerWithJava mediaPanel = new SimpleVideoPlayerWithJava(mediaUrl);
mediaTest.add(mediaPanel);
mediaTest.setSize(800, 700); // set the size of the player
mediaTest.setLocationRelativeTo(null);
mediaTest.setVisible(true);
}
}
wyskakuje taki błąd:
Exception in thread "main" java.lang.IllegalArgumentException: Container must be non-null
at javax.swing.GroupLayout.<init>(GroupLayout.java:374)
at SimpleVideoPlayerWithJava.SimpleVideoPlayerWithJava.initComponents(SimpleVideoPlayerWithJava.java:48)
at SimpleVideoPlayerWithJava.SimpleVideoPlayerWithJava.<init>(SimpleVideoPlayerWithJava.java:17)
at SimpleVideoPlayerWithJava.SimpleVideoPlayerWithJava.main(SimpleVideoPlayerWithJava.java:112)
C:\Users\Tomas\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 6 seconds)