使用 VLCJ 将视频播放器添加到 Java 中的 JPanel [英] Adding a video player to a JPanel in java using VLCJ

查看:43
本文介绍了使用 VLCJ 将视频播放器添加到 Java 中的 JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有两件想要合并的作品.我有一个在 JFrame 中运行的简单媒体播放器和一个 GUI,我想在 JPanel 上添加视频播放.

I am currently in the position of having 2 pieces of work I wish to combine. I have a simple media player running in a JFrame and a GUI I would like to add video playback to on a JPanel.

创建视频播放器窗口的代码如下:

The code for the which creates video player window is as follows:

private final JFrame vidFrame;
private final EmbeddedMediaPlayerComponent vidComp;

//Creates JPanel for video player
public Video() {

    vidFrame = new JFrame("VLC video test");
    vidFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    vidFrame.setLocation(100, 100);
    vidFrame.setSize(800, 800);

    vidComp = new EmbeddedMediaPlayerComponent();

    //This is the point where I am trying to add the video player to the GUI
    MainWindow.vidPanel.add(vidComp);

    vidFrame.add(vidComp);
    vidFrame.setVisible(true);
}

这是我尝试将播放器添加到的面板:

And this is the panel I'm trying to add the player to:

    JPanel vidPanel = new JPanel();
    vidPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    vidPanel.setBounds(10, 11, 532, 400);
    contentPane.add(vidPanel);

我收到错误消息:vidPanel 无法解析或不是字段"

I get the error message: "vidPanel cannot be resolved or is not a field"

有谁知道我该如何纠正这个问题?

Does anyone know how I can rectify this?

推荐答案

首先,看起来你的 vidPanel 是一个局部变量,如果你需要从其他方法访问它应该是一个字段.这是 Java 的一个非常基本的部分 - 任何初学者教程都应该涵盖这一点.VLCJ 不是最容易使用的东西,如果您不清楚基本原理,您可能会不知所措.

Firstly, it looks like your vidPanel is a local variable and should be a field if you need to access it from other methods. This is a pretty basic piece of Java - any beginners tutorial should cover this. VLCJ isn't the simplest thing to use and you may come unstuck if you're not clear on the fundamentals.

其次,在您走得太远之前,嵌入式 VLCJ 播放器无法与 JPanel 配合使用,而只能使用本机 AWT Canvas - 因此您需要改用它.

Secondly, before you head too far down that track, an embedded VLCJ player doesn't work with a JPanel, just a native AWT Canvas - so you'll need to use that instead.

这篇关于使用 VLCJ 将视频播放器添加到 Java 中的 JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆