Created
March 26, 2019 13:29
-
-
Save leon-lourenco/cd0aed1b3d0d3153e20e50ed6ad87ccd to your computer and use it in GitHub Desktop.
A embed YouTube video on a Swing application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using Dj Project library