1

如何在 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);
    }
}

这是结果:

结果 http://vitamin.vipdesign.com.ua/1n7tJ.jpg

4

1 回答 1

2

You need to take the time to read the vlcj wiki

You can not simply add a lightweight transparent JComponent on top of the heavyweight video surface Canvas component - it will not work.

Which is what I suspected from the earlier post on the same subject

Check out Overlaying Graphics for more details

于 2013-06-05T06:43:34.787 回答