Browse Source

Embedded video player (#421)

pull/424/head
Cromefire_ 4 years ago committed by GitHub
parent
commit
3812ab11c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      components/VideoPlayer/common/src/desktopMain/kotlin/org/jetbrains/compose/videoplayer/DesktopVideoPlayer.kt

21
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)
SideEffect {
val ok = mediaPlayerComponent.mediaPlayer().media().play(url)
println("play gave $ok")
}
return SwingPanel(
background = Color.Transparent,
modifier = Modifier.fillMaxSize(),
componentBlock = {
mediaPlayerComponent
}
)
}

Loading…
Cancel
Save