From 42cb79609ab01c6f3341bd632c7f5bfbe48c2929 Mon Sep 17 00:00:00 2001 From: xiaji Date: Tue, 9 Jun 2026 19:54:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20PlayerActivity=20=E4=BD=BF=E7=94=A8=20S?= =?UTF-8?q?ourceHandler=20=E8=8E=B7=E5=8F=96=E5=89=A7=E9=9B=86=E5=92=8C?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/videoapp/tv/PlayerActivity.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/videoapp/tv/PlayerActivity.kt b/app/src/main/java/com/videoapp/tv/PlayerActivity.kt index 8aff822..54b77c2 100644 --- a/app/src/main/java/com/videoapp/tv/PlayerActivity.kt +++ b/app/src/main/java/com/videoapp/tv/PlayerActivity.kt @@ -26,7 +26,7 @@ import com.videoapp.tv.data.ConfigRepository import com.videoapp.tv.data.PlayHistory import com.videoapp.tv.engine.Episode import com.videoapp.tv.engine.PlaySource -import com.videoapp.tv.engine.VideoExtractor +import com.videoapp.tv.engine.SourceRegistry import kotlinx.coroutines.launch class PlayerActivity : AppCompatActivity() { @@ -43,7 +43,6 @@ class PlayerActivity : AppCompatActivity() { private lateinit var brightnessVolumeIndicator: TextView private var exoPlayer: ExoPlayer? = null - private val videoExtractor = VideoExtractor() private val configRepo by lazy { ConfigRepository(this) } private val playHistoryDao by lazy { AppDatabase.getInstance(this).playHistoryDao() } private val audioManager by lazy { getSystemService(Context.AUDIO_SERVICE) as AudioManager } @@ -140,18 +139,19 @@ class PlayerActivity : AppCompatActivity() { private fun loadSources(detailUrl: String) { showLoading(true) - val config = configRepo.getConfig() + val currentId = configRepo.getCurrentSourceId() + val handler = SourceRegistry.getOrDefault(currentId) lifecycleScope.launch { try { - sources = videoExtractor.extractVideos(detailUrl, config) + sources = handler?.extractVideos(detailUrl) ?: emptyList() if (sources.isNotEmpty()) { buildSourceUI() selectSource(0) resetAutoHide() } else { - tryPlayDirectly(detailUrl, config) + tryPlayDirectly(detailUrl) } } catch (e: Exception) { showError("加载失败: ${e.message}") @@ -247,24 +247,21 @@ class PlayerActivity : AppCompatActivity() { private fun playEpisode(ep: Episode) { currentEpisode = ep showLoading(true) - val config = configRepo.getConfig() + val currentId = configRepo.getCurrentSourceId() + val handler = SourceRegistry.getOrDefault(currentId) savePlayHistory(ep.title) lifecycleScope.launch { - val (directUrl, iframeUrl) = videoExtractor.extractFromPlayPage(ep.playUrl, config) + val (directUrl, iframeUrl) = handler?.resolvePlayUrl(ep.playUrl) + ?: Pair(null, null) if (directUrl != null) { playWithExoPlayer(directUrl) } else if (iframeUrl != null) { playWithWebView(iframeUrl) } else { - val apiUrl = videoExtractor.fetchPlayUrlFromApi(ep.playUrl, config.baseUrl) - if (apiUrl != null) { - playWithExoPlayer(apiUrl) - } else { - playWithWebView(ep.playUrl) - } + playWithWebView(ep.playUrl) } } } @@ -319,11 +316,14 @@ class PlayerActivity : AppCompatActivity() { positionSaveHandler.removeCallbacks(positionSaveRunnable) } - private fun tryPlayDirectly(detailUrl: String, config: com.videoapp.tv.data.SiteConfig) { + private fun tryPlayDirectly(detailUrl: String) { savePlayHistory(videoTitle) lifecycleScope.launch { - val (directUrl, iframeUrl) = videoExtractor.extractFromPlayPage(detailUrl, config) + val currentId = configRepo.getCurrentSourceId() + val handler = SourceRegistry.getOrDefault(currentId) + val (directUrl, iframeUrl) = handler?.resolvePlayUrl(detailUrl) + ?: Pair(null, null) if (directUrl != null) { controlPanel.visibility = View.GONE playWithExoPlayer(directUrl)