在JPanel中嵌入VLCJ [英] Embedding VLCJ in JPanel

查看:176
本文介绍了在JPanel中嵌入VLCJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读此SO线程当我尝试使用代码进行一些更改时,我只是一个黑色的窗口,有人可以告诉我这里我做错了什么,我只有一个主要功能的类: / p>

I have read this SO thread and when I have tried to use the code with some changes, I'm getting just a black window, can some one tell me what I'm doing wrong here, I have just one class with main function :

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sun.jna.NativeLibrary;

import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
import uk.co.caprica.vlcj.runtime.windows.WindowsCanvas;

public class Canvas_Demo {

    // Create a media player factory
    private MediaPlayerFactory mediaPlayerFactory;

    // Create a new media player instance for the run-time platform
    private EmbeddedMediaPlayer mediaPlayer;

    private JPanel panel;
    private WindowsCanvas canvas;
    private JFrame frame;

    //Constructor
    public Canvas_Demo(String url){

        //Creating a panel that while contains the canvas
        panel = new JPanel();
        panel.setBackground(Color.BLACK);

        //Creating the canvas and adding it to the panel :
        canvas = new WindowsCanvas();
        panel.add(canvas);
        panel.revalidate();
        panel.repaint();

        //Creation a media player :
        mediaPlayerFactory = new MediaPlayerFactory();
        mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
        CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);
        mediaPlayer.setVideoSurface(videoSurface);

        //Construction of the jframe :
        frame = new JFrame("Demo with Canvas AWT");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation(100, 100);
        frame.setSize(700, 500);

        //Adding the panel to the 
        frame.add(panel);
        frame.setVisible(true);

        //Playing the video
        mediaPlayer.playMedia(url);


    }
    //Main function :
    public static void main(String[] args) {
        NativeLibrary.addSearchPath("libvlc", "C:/Program Files/VideoLAN/VLC");

        final String url = "C:/MyVideo.mp4";

        new Canvas_Demo(url);

    }

}

提前致谢。

推荐答案

当我将视频网址(也称为MRL作为媒体资源定位器)更改为: C:\\MyVideo.mp4 我在窗口中收到了视频。

When I change the video url (also called MRL as Media Ressource Locator) to this : C:\\MyVideo.mp4 I got the video in the window.

这个讨论帮助了我。

这篇关于在JPanel中嵌入VLCJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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