caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.1k stars 260 forks source link

How to set the transparency for EmbeddedMediaPlayerComponent? #1226

Closed wang1231 closed 1 month ago

wang1231 commented 2 months ago

How to set the transparency for EmbeddedMediaPlayerComponent? The code below doesn't work, thank you.

java mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); mediaPlayerComponent.setOpaque(true); mediaPlayerComponent.videoSurfaceComponent().setBackground(Color.BLACK);

wang1231 commented 2 months ago

I have overlaid a custom text panel component on a player. When overlaying this component on an image, the text is displayed on the image as expected. However, when overlaying it on the player, the text does not display over the video. Instead, the area of the custom text component is blocking the video image. What could be the reason for this? I'm not sure if I've explained this clearly.

caprica commented 2 months ago

This is a well-known problem.

You simply can not do this since the video surface is a "heavyweight" AWT Canvas component, that VLC natively renders directly into. There is no compositing available.

For this reason, there is an Overlay feature provided by vlcj, but it is sub-optimal because it does nasty things like overlaying a top-level transparent Window and keeping it in position by listening to window drag and resize events. It does kinda work, but it's also not very nice. It is good enough for some people's use cases.

The only other option is to use software rendering via JavaFX or the Graphics2D video surface, but here YOU are responsible for rendering the video, so performance is not as good.

The "best" way, to keep native performance, is to use the logo and marquee APIs.

wang1231 commented 2 months ago

I attempted to use Swing's layer management layout, with a background image at the bottom, the player in the middle, and a text panel on top. Surprisingly, the area of the text panel penetrates through the player layer, revealing the background image underneath. What could be the reason for this? Thank you.

caprica commented 2 months ago

I have no idea. What I told you about Canvas is the root of this problem.