Skip to content

Instantly share code, notes, and snippets.

@leon-lourenco
Created March 26, 2019 13:29
Show Gist options
  • Save leon-lourenco/cd0aed1b3d0d3153e20e50ed6ad87ccd to your computer and use it in GitHub Desktop.
Save leon-lourenco/cd0aed1b3d0d3153e20e50ed6ad87ccd to your computer and use it in GitHub Desktop.
A embed YouTube video on a Swing application
public class YouTubeViewer {
public static void main(String[] args) {
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("YouTube Viewer");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(getBrowserPanel(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
// don't forget to properly close native components
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
NativeInterface.close();
}
}));
}
public static JPanel getBrowserPanel() {
JPanel webBrowserPanel = new JPanel(new BorderLayout());
JWebBrowser webBrowser = new JWebBrowser();
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
webBrowser.navigate("https://www.youtube.com/v/b-Cr0EWwaTk?fs=1");
return webBrowserPanel;
}
}
@leon-lourenco
Copy link
Author

using Dj Project library

@davidchidu1
Copy link

And which one is it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment