feat: PlayerActivity 使用 SourceHandler 获取剧集和播放链接
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user