From 3812ab11c0978a8edd68f29c2958fa1298c5210e Mon Sep 17 00:00:00 2001 From: Cromefire_ Date: Wed, 24 Feb 2021 19:07:22 +0100 Subject: [PATCH] Embedded video player (#421) --- .../compose/videoplayer/DesktopVideoPlayer.kt | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/components/VideoPlayer/common/src/desktopMain/kotlin/org/jetbrains/compose/videoplayer/DesktopVideoPlayer.kt b/components/VideoPlayer/common/src/desktopMain/kotlin/org/jetbrains/compose/videoplayer/DesktopVideoPlayer.kt index 26199f5b47..fec7134aa2 100644 --- a/components/VideoPlayer/common/src/desktopMain/kotlin/org/jetbrains/compose/videoplayer/DesktopVideoPlayer.kt +++ b/components/VideoPlayer/common/src/desktopMain/kotlin/org/jetbrains/compose/videoplayer/DesktopVideoPlayer.kt @@ -1,7 +1,11 @@ package org.jetbrains.compose.videoplayer - + +import androidx.compose.desktop.SwingPanel +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable -import javax.swing.JFrame +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent @@ -10,13 +14,16 @@ internal actual fun VideoPlayerImpl(url: String, width: Int, height: Int) { println("Video player for $url") NativeDiscovery().discover() // Doesn't work on macOS, see https://github.com/caprica/vlcj/issues/887 for suggestions. - val frame = JFrame() val mediaPlayerComponent = EmbeddedMediaPlayerComponent() - frame.contentPane = mediaPlayerComponent - frame.setLocation(0, 0) - frame.setSize(width,height) - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) - frame.setVisible(true) - val ok = mediaPlayerComponent.mediaPlayer().media().play(url) - println("play gave $ok") + SideEffect { + val ok = mediaPlayerComponent.mediaPlayer().media().play(url) + println("play gave $ok") + } + return SwingPanel( + background = Color.Transparent, + modifier = Modifier.fillMaxSize(), + componentBlock = { + mediaPlayerComponent + } + ) }