我一直试图通过Java播放视频。我正在使用DJ Native swing来播放视频。以下代码编译时没有任何错误,但它没有加载视频。
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JVLCPlayer;
import javax.swing.*;
import java.awt.*;
public class VideoPlayer extends Thread{
public static void start(final String title) {
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.getContentPane().add(getBrowserPanel(title), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
}
public void close(){
NativeInterface.runEventPump();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
NativeInterface.close();
}
}));
}
public static JPanel getBrowserPanel(String url) {
JPanel webBrowserPanel = new JPanel(new BorderLayout());
JVLCPlayer jvlcPlayer=new JVLCPlayer();
webBrowserPanel.add(jvlcPlayer, BorderLayout.CENTER);
jvlcPlayer.load("filename");
jvlcPlayer.setControlBarVisible(true);
return webBrowserPanel;
}
}