在顶级vlcj MediaPlayer上添加透明Swing组件?

时间:2013-06-05 05:22:30

标签: java swing jlabel vlcj

如何在vlcj MediaPlayer上添加透明背景的JLabel?

我把源码放在下面,但它没有正常工作,因为JLabel没有透明的背景设置。

import com.sun.jna.NativeLibrary;
import javax.swing.*;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

class VideoExample extends JFrame {

    private EmbeddedMediaPlayerComponent mediaPlayerComponent;

    public VideoExample(String path) {
        super("Простой видео плеер");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(640, 480);

        //Create JLayeredPane 
        JLayeredPane mainLayer = new JLayeredPane();
        mainLayer.setSize(640,480);

        //Create MediaPlayer on background
        mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        mediaPlayerComponent.setLocation(0, 0);
        mediaPlayerComponent.setSize(mainLayer.getSize());

        //Create MediaPlayer on foreground
        JLabel label = new JLabel("LABEL", JLabel.CENTER);
        label.setBounds(100, 100, 200, 100);
        label.setOpaque(false);

        mainLayer.add(mediaPlayerComponent, JLayeredPane.DEFAULT_LAYER); //add mediaPlayer in DEFAULT_LAYER
        mainLayer.add(label, JLayeredPane.PALETTE_LAYER); //add label in PALETTE_LAYER
        add(mainLayer); // add JLayeredPane in JFrame 

        setVisible(true);
        mediaPlayerComponent.getMediaPlayer().playMedia(path);
    }

    public static void main(String[] args) {
        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), System.getProperty("user.dir") + "/lib/vlc64");
        final String mrl = "D:\\Candlelight_QT.mov";
        new VideoExample(mrl);
    }
}

结果如下:

The result http://vitamin.vipdesign.com.ua/1n7tJ.jpg

1 个答案:

答案 0 :(得分:2)

您需要花时间阅读vlcj wiki

  

你不能简单地在上面添加一个轻量级的透明JComponent   重量级视频表面Canvas组件 - 它不起作用。

这是我在同一主题的早期帖子中所怀疑的

查看Overlaying Graphics了解详情