I'm trying to get video playing in compose desktop...
# compose-desktop
z
I'm trying to get video playing in compose desktop by utilizing the mpv opengl rendering API. Theoretically I can render to a skia surface and display that in compose all without using SwingPanel are there any examples of interacting directly with opengl others could share? I'm aware of the lwjgl example which does help me but thats more like wrapping the entire compose app with lwjgi. I just need to somehow connect the skia surface to a compose component now
đź‘€ 1
k
Probably somewhere around https://github.com/JetBrains/skiko/blob/master/skiko/src/commonMain/kotlin/org/jetbrains/skia/Surface.kt#L270 where opengl would be rendering into that frame buffer. You might end up reimplementing most if not all of the implementation of
SwingPanel
to get it all working. Is there a particular reason why you don’t want to use
SwingPanel
or the code in
lwjgl
? Do you have a working proof of concept that shows that these two can be cut out without borrowing much of their code?
l
When I worked on a video player in compose, I found writing to an ImageBitmap, and showing that to be surprisingly performant. The main gist was getting an ARGB byte array from my library (FFmpeg in my case) and using that to create an ImageBitmap. I forget the exact method name.
i
Please note that render something above that view via Compose might not be trivial. I'd suggest you to render it offscreen/to texture first to get predictable cross platform blending/overlapping
z
@Kirill Grouchnikov I'm avoiding SwingPanel since compose can't render on top of it which prevents making the control UI using compose
z
jpanel has the problem of hiding any compose stuff like tooltips. and has other issues.
@zt i would be very interested in something like this. i also am rendering YUV video frames with cpu into a jpanel. which is ok, but uses lots of CPU. can you link to your code repo? is it open source?
i
@Zoff - It was documented behaviour, but there are who related changes recently: • Drawing above interop - has some limitations, requires enabling offscreen rendering on linux • Optional showing Dialog/Popup as separate panel or even window - experimental, details will be on the page about 1.6.0 from our tech writers
m
@Ivan Matkov Where can I learn more about this “popup as separate panel or window” feature? The PR is light on details. Will this fix the issue that tooltips cannot extend past the edge of the window?
i
Where can I learn more about this “popup as separate panel or window” feature?
Docs are in process, it will be public soon. Let me find my draft
Will this fix the issue that tooltips cannot extend past the edge of the window?
yes, but please note that most of material built-in components has default logic to fit it to the size of the screen
Desktop - In EXPERIMENTAL stage and under the flag. It can be enabled by changing the
compose.layers.type
system property. The possible values are: 1.
COMPONENT
- for creating Popup/Dialog as a separate Swing component in the same window. It might work only with offscreen rendering. 2.
WINDOW
- for creating Popup/Dialog as a separate undecorated window. 3. any other value - the old behavior that draws everything in the initial canvas.
ComposePanel.windowContainer
- API for customizing parent container for Popup/Dialog. Used only with
COMPONENT
type.
m
I don’t use Material in my project, all my components are based on Foundation composables. But I had the issue with tooltips and dropdowns when near the edge of the window being forced back inside the window. This looks promising!
i
image.png
🤩 2
Please note that it's in experimental stage. Looking forward for your feedback
m
Is there some experimental release I can try in my project, or is it too early?
i
1.6.0
m
Oh so it’s just a matter of using the flag. I will give it a go!
đź‘Ť 1
i
Also you might be interested in disabling built-in
Popup
clamping via
PopupProperties.clippingEnabled
flag
m
Unfortunately it doesn't seem to work correctly, at least on Linux. I used the
WINDOW
mode, but my context menus (Popups) don't render their content.
i
Please file an issue. Does manually created transparent undecorated window with Compose work for you?
m
Undecorated windows work fine, but transparent ones have issues on Linux (which I think got fixed in JDK 22, but I haven't tried it myself). Why are transparent windows needed here?
i
To respect round corners etc
m
Makes sense. Maybe it could be optional, with another
WINDOW_OPAQUE
mode? My non-Material tooltips and dropdowns don't have rounded corners anyway. Not sure if that's the actual issue though. I will experiment more and open an issue.
🤔 1
Would be useful to try without transparency to see if that's the issue or not.