mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 15:32:01 +00:00
feat: prewarming dylib
This commit is contained in:
parent
72dfbac9a9
commit
89ca233f71
5 changed files with 57 additions and 1 deletions
|
|
@ -27,6 +27,11 @@ public func nuvio_player_create() -> UnsafeMutableRawPointer {
|
|||
return Unmanaged.passRetained(p).toOpaque()
|
||||
}
|
||||
|
||||
@_cdecl("nuvio_player_prewarm")
|
||||
public func nuvio_player_prewarm() {
|
||||
NuvioPlayerPrewarmer.shared.prewarm()
|
||||
}
|
||||
|
||||
@_cdecl("nuvio_player_destroy")
|
||||
public func nuvio_player_destroy(_ ptr: UnsafeMutableRawPointer) {
|
||||
let p = Unmanaged<NuvioPlayerWindow>.fromOpaque(ptr).takeRetainedValue()
|
||||
|
|
|
|||
20
MPVKit/Sources/DesktopMPVBridge/NuvioPlayerPrewarmer.swift
Normal file
20
MPVKit/Sources/DesktopMPVBridge/NuvioPlayerPrewarmer.swift
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import AppKit
|
||||
|
||||
final class NuvioPlayerPrewarmer {
|
||||
static let shared = NuvioPlayerPrewarmer()
|
||||
|
||||
private var started = false
|
||||
|
||||
private init() {
|
||||
}
|
||||
|
||||
func prewarm() {
|
||||
DispatchQueue.main.async {
|
||||
guard !self.started else { return }
|
||||
self.started = true
|
||||
let view = NuvioMPVView(frame: NSRect(x: 0, y: 0, width: 16, height: 16))
|
||||
view.setup()
|
||||
view.destroyPlayer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
package com.nuvio.app
|
||||
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import com.nuvio.app.features.player.prewarmDesktopPlaybackBackend
|
||||
import java.awt.Color as AwtColor
|
||||
|
||||
private val DesktopWindowBackground = AwtColor(0x0D, 0x0D, 0x0D)
|
||||
|
|
@ -27,7 +29,11 @@ fun main() {
|
|||
onDispose { }
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
prewarmDesktopPlaybackBackend()
|
||||
}
|
||||
|
||||
App()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.nuvio.app.features.player
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
private val desktopPlaybackPrewarmStarted = AtomicBoolean(false)
|
||||
|
||||
internal suspend fun prewarmDesktopPlaybackBackend() {
|
||||
val osName = System.getProperty("os.name").orEmpty().lowercase()
|
||||
if (!osName.contains("mac")) return
|
||||
if (!desktopPlaybackPrewarmStarted.compareAndSet(false, true)) return
|
||||
|
||||
val bridge = withContext(Dispatchers.IO) {
|
||||
runCatching { MacOSMPVBridgeLib.INSTANCE }.getOrNull()
|
||||
} ?: return
|
||||
|
||||
delay(1_500)
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
runCatching { bridge.nuvio_player_prewarm() }
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ internal interface MacOSMPVBridgeLib : Library {
|
|||
}
|
||||
|
||||
fun nuvio_player_create(): Pointer
|
||||
fun nuvio_player_prewarm()
|
||||
fun nuvio_player_destroy(player: Pointer)
|
||||
fun nuvio_player_show(player: Pointer)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue