将视频嵌入JFrame?

Rya*_*yan 7 java youtube-api

我一直在做很多研究,并试图找到一个指南,可以教我如何正确地将YouTube视频直接嵌入到我的视频中JFrame.我已经阅读了YouTube API上的所有Google Developers指南,但找不到我想要做的事情.

我正在尝试将YouTube视频直接嵌入到JFrame我的主要方法中使用init.例如:

/**
 * 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我发起我的世界选择界面的地方,我希望有" initYouTubeVideo"

我创建了一个虚空" initYouTubeVideo",并不完全理解我如何嵌入视频和视频.说我为我的游戏做了更新,我制作了一个关于它的YouTube视频.我想在我的视频中播放该视频JFrame(没有评论部分或其他任何仅仅是YouTube视频).

有人可以给我一个指南,我可以直接学习如何嵌入YouTube视频.

对于这篇文章,我做了一个示例JFrame,以帮助您在视觉上理解我正在努力实现的目标.这是图片:

图片

在图像中,红色是我放置YouTube播放器的地方,绿色是我的界面.现在再次说我在我的游戏中做了一个更新并制作了一个关于它的YouTube视频.我希望能够将链接添加到视频中,当有人运行客户端时,他们可以点击播放并观看视频.

注意:我使用的是Google的YouTube API

我查看了以下指南:有关YouTube API的所有信息,请访问:https://developers.google.com/youtube/v3/getting-started

我想要的只是将视频添加到JFrame,以便我的玩家可以获得有关最新游戏内容的视频更新.

谢谢你和代表那些可以帮助我的人.

Jk1*_*Jk1 10

这是我通常用于将YouTube视频嵌入Swing应用程序的方式.

使用DJ Native Swing将本机浏览器组件嵌入到JPanel中,而不是使用YouTube API :

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;
}
}
Run Code Online (Sandbox Code Playgroud)

运行时看起来像

在此输入图像描述

启动上面的示例需要以下库:

  • DJNativeSwing.jar
  • DJNativeSwing-SWT.JAR
  • swt-4.3-win32-win32-x86.jar(这个是平台相关的)

你可以从DJ Native Swing下载包中获取所有这些内容.