如何在 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);
}
}
这是结果: