还有其他方法可以在java面板上输出Web视频流吗?



我编写的代码是,当我单击java摇摆按钮时,JAVA会播放python客户端发送到Web的视频流。(我使用 vlcj 和 mjpg-streamer 在 java swing JFrame 上播放视频流。

不幸的是,它占用了所有JFrame空间,但我想使JFrame播放视频流的一部分,例如JPanel之类的。我想知道是否有其他方法可以让 JPanel 播放视频流。希望您帮助我,并感谢您的阅读。

下面是我使用 JFrame、VLCJ 的代码。

SearchIcon2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String number = CCTV.getSelectedItem().toString();
                if (number.equals("no. 1")) {
                    EmbeddedMediaPlayerComponent component = new EmbeddedMediaPlayerComponent();
                    final JFrame fs = new JFrame("no. 1");
                    fs.setContentPane(component);
                    fs.setBounds(100, 100, 850, 518);
                    fs.setResizable(false);
                    fs.setLocationRelativeTo(null);
                    fs.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            component.release();
                            fs.setVisible(false);
                            fs.dispose();
                        }
                    });
                    fs.setVisible(true);
                    component.mediaPlayer().media().play("http://IP:8090/?action=stream"); // sorry it is my ip.
                }
            }
        });

您将component添加为内容窗格,因此它涵盖了所有 JFrame。

您可以使用 JFrame 的布局管理器(默认为 BorderLayout(,也可以添加 JPanel 作为内容窗格,并使用布局管理器添加其他组件。

// JFrame layout example
final JFrame fs = new JFrame("no. 1");
fs.add(component, BorderLayout.CENTER);
fs.add(newPanel, BorderLayout.SOUTH);

// JPanel example
JPanel panel = new JPanel();
LayoutManager mgr = ...
panel.setLayout(mgr);
panel.add(component); // maybe layout manager specific parameters also
fs.setContentPane(panel);

最新更新