将YouTube视频嵌入JFrame? [英] Embed a YouTube video to JFrame?
问题描述
我一直在做很多研究,并试图找到一个指南,可以教我如何正确地将YouTube视频直接嵌入我的 JFrame
。我已经阅读了 YouTube API 上的所有Google Developers指南,但找不到我想要做的事情。
I've been doing a lot of research and trying to find a guide that can teach me how to correctly embed a YouTube video directly to my JFrame
. I've read all of the Google Developers guides on the YouTube API but can't find just what I'm looking to do.
我正在尝试使用我的main方法中的init将YouTube视频直接嵌入 JFrame
。例如:
I'm trying to embed a YouTube video straight to the JFrame
using an init in my main method. For example:
/**
* Main
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (UnsupportedLookAndFeelException ulafe) {
Loader loader = new Loader();
loader.doFrame();
}
Start Loader = new Start();
Loader.setVisible(true);
}
/**
* Start
* @throws IOException
*/
public Start() throws IOException {
super("Ryan's Client Launcher version: '0.0.1'");
try {
getContentPane().setBackground(Color.BLACK);
setBackground(Color.BLACK);
BufferedImage image39 = ImageIO.read(getClass().getResourceAsStream("\\jaggl\\igs\\39.png"));
this.setIconImage(image39);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(new Dimension(launcherWidth, launcherHeight));
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setUndecorated(true);
getContentPane().setLayout(null);
initWorldSelectInterface();
} catch (IOException e) {
System.out.println(e);
}
}
在我发起我的世界选择界面的地方我会喜欢 initYouTubeVideo
Under where I have initiated my world select interface I would like to have "initYouTubeVideo
"
我创建了一个空白 initYouTubeVideo
并且不完全理解我如何才能嵌入视频和放大器只有视频。说我为我的游戏做了更新我制作了一段关于它的YouTube视频。我想在我的 JFrame
上播放该视频(没有评论部分或任何其他只是YouTube视频)。
I've created a void "initYouTubeVideo
" and don't exactly understand how I can just embed the video & only the video. Say I make an update for my game & I make a YouTube video about it. I'd like to feature that video on my JFrame
(no comment Section or anything else just simply the YouTube video).
有人可以给我一个指南,我可以直接了解如何嵌入YouTube视频。
Could someone please give me a guide that I can learn from directly on how to Embed the YouTube video.
对于这篇文章我做了一个示例JFrame来帮助你在视觉上理解我正在努力实现的目标。这是图片:
For this post I made an example JFrame to help you visually understand what I'm trying to accomplish. Here is the Image:
在图像中,红色是放置YouTube播放器和放置的位置。绿色是我的界面。现在再次说我在我的游戏中进行了更新。制作了关于它的YouTube视频。我希望能够将视频链接放入&当有人运行客户端时,他们可以点击播放&观看视频。
In the image the red is where I would place the YouTube player & The green is my interfaces. Now again say I made an update in my game & made a youtube video about it. I want to be able to just put the link to the video in & when someone runs the client they can click play & watch the video.
注意:我使用 Google的YouTube API
I已查看以下指南:
此处可找到有关YouTube API的所有内容: https: //developers.google.com/youtube/v3/getting-started
I have looked at the following Guides: Everything about the YouTube API found here: https://developers.google.com/youtube/v3/getting-started
再次我想要的只是将视频添加到JFrame所以我的播放器可以获得最新游戏内容的视频更新。
Again All i want is just to add the video to the JFrame so my players can get video updates on the latest game content.
谢谢你&代表那些可以帮助我的人。
Thank you & Rep to those that can help me.
推荐答案
以下是我通常用于将YouTube视频嵌入Swing应用程序的方式。
Here's the way I usualy use to embed YouTube videos into Swing application.
使用 DJ Native Swing :
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;
}
}
运行时看起来像
上面的示例需要以下库:
The following libraries are necessary to launch an example above:
- DJNativeSwing.jar
- DJNativeSwing-SWT.jar
- swt-4.3-win32-win32-x86.jar(这个是平台相关的)
你可以从DJ Native Swing下载包中获得所有这些。
you can get all of them from a DJ Native Swing download package.
这篇关于将YouTube视频嵌入JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!