package eu.friedcutlet.yokan.services.media.player import eu.friedcutlet.yokan.services.system.openSystemBrowser import io.ktor.http.encodeURLParameter /** URL-scheme players; each scheme is listed in Info.plist `LSApplicationQueriesSchemes`. */ private val IosPlayers = listOf( ExternalPlayerChoice("vlc", "VLC") to { url: String -> "vlc-x-callback://x-callback-url/stream?url=${url.encodeURLParameter()}" }, ExternalPlayerChoice("infuse", "Infuse") to { url: String -> "infuse://x-callback-url/play?url=${url.encodeURLParameter()}" }, ExternalPlayerChoice("outplayer", "Outplayer") to { url: String -> "outplayer://$url" }, ) actual fun externalPlayerChoices(): List = IosPlayers.map { it.first } + ExternalPlayerChoice("system", "System default") actual fun launchExternalPlayer(url: String, headers: Map, playerId: String): Boolean { // iOS won't honor per-request HTTP headers via openURL; the proxy URL // already has them injected, so a blank id hands it to the default // handler — VLC / Infuse / etc. will pick it up if installed. val player = IosPlayers.firstOrNull { it.first.id == playerId } ?: return openSystemBrowser(url) return openSystemBrowser(player.second(url)) }