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.data.PlayHistory
|
||||||
import com.videoapp.tv.engine.Episode
|
import com.videoapp.tv.engine.Episode
|
||||||
import com.videoapp.tv.engine.PlaySource
|
import com.videoapp.tv.engine.PlaySource
|
||||||
import com.videoapp.tv.engine.VideoExtractor
|
import com.videoapp.tv.engine.SourceRegistry
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class PlayerActivity : AppCompatActivity() {
|
class PlayerActivity : AppCompatActivity() {
|
||||||
@@ -43,7 +43,6 @@ class PlayerActivity : AppCompatActivity() {
|
|||||||
private lateinit var brightnessVolumeIndicator: TextView
|
private lateinit var brightnessVolumeIndicator: TextView
|
||||||
|
|
||||||
private var exoPlayer: ExoPlayer? = null
|
private var exoPlayer: ExoPlayer? = null
|
||||||
private val videoExtractor = VideoExtractor()
|
|
||||||
private val configRepo by lazy { ConfigRepository(this) }
|
private val configRepo by lazy { ConfigRepository(this) }
|
||||||
private val playHistoryDao by lazy { AppDatabase.getInstance(this).playHistoryDao() }
|
private val playHistoryDao by lazy { AppDatabase.getInstance(this).playHistoryDao() }
|
||||||
private val audioManager by lazy { getSystemService(Context.AUDIO_SERVICE) as AudioManager }
|
private val audioManager by lazy { getSystemService(Context.AUDIO_SERVICE) as AudioManager }
|
||||||
@@ -140,18 +139,19 @@ class PlayerActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun loadSources(detailUrl: String) {
|
private fun loadSources(detailUrl: String) {
|
||||||
showLoading(true)
|
showLoading(true)
|
||||||
val config = configRepo.getConfig()
|
val currentId = configRepo.getCurrentSourceId()
|
||||||
|
val handler = SourceRegistry.getOrDefault(currentId)
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
sources = videoExtractor.extractVideos(detailUrl, config)
|
sources = handler?.extractVideos(detailUrl) ?: emptyList()
|
||||||
|
|
||||||
if (sources.isNotEmpty()) {
|
if (sources.isNotEmpty()) {
|
||||||
buildSourceUI()
|
buildSourceUI()
|
||||||
selectSource(0)
|
selectSource(0)
|
||||||
resetAutoHide()
|
resetAutoHide()
|
||||||
} else {
|
} else {
|
||||||
tryPlayDirectly(detailUrl, config)
|
tryPlayDirectly(detailUrl)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showError("加载失败: ${e.message}")
|
showError("加载失败: ${e.message}")
|
||||||
@@ -247,24 +247,21 @@ class PlayerActivity : AppCompatActivity() {
|
|||||||
private fun playEpisode(ep: Episode) {
|
private fun playEpisode(ep: Episode) {
|
||||||
currentEpisode = ep
|
currentEpisode = ep
|
||||||
showLoading(true)
|
showLoading(true)
|
||||||
val config = configRepo.getConfig()
|
val currentId = configRepo.getCurrentSourceId()
|
||||||
|
val handler = SourceRegistry.getOrDefault(currentId)
|
||||||
|
|
||||||
savePlayHistory(ep.title)
|
savePlayHistory(ep.title)
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val (directUrl, iframeUrl) = videoExtractor.extractFromPlayPage(ep.playUrl, config)
|
val (directUrl, iframeUrl) = handler?.resolvePlayUrl(ep.playUrl)
|
||||||
|
?: Pair(null, null)
|
||||||
|
|
||||||
if (directUrl != null) {
|
if (directUrl != null) {
|
||||||
playWithExoPlayer(directUrl)
|
playWithExoPlayer(directUrl)
|
||||||
} else if (iframeUrl != null) {
|
} else if (iframeUrl != null) {
|
||||||
playWithWebView(iframeUrl)
|
playWithWebView(iframeUrl)
|
||||||
} else {
|
} else {
|
||||||
val apiUrl = videoExtractor.fetchPlayUrlFromApi(ep.playUrl, config.baseUrl)
|
playWithWebView(ep.playUrl)
|
||||||
if (apiUrl != null) {
|
|
||||||
playWithExoPlayer(apiUrl)
|
|
||||||
} else {
|
|
||||||
playWithWebView(ep.playUrl)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,11 +316,14 @@ class PlayerActivity : AppCompatActivity() {
|
|||||||
positionSaveHandler.removeCallbacks(positionSaveRunnable)
|
positionSaveHandler.removeCallbacks(positionSaveRunnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryPlayDirectly(detailUrl: String, config: com.videoapp.tv.data.SiteConfig) {
|
private fun tryPlayDirectly(detailUrl: String) {
|
||||||
savePlayHistory(videoTitle)
|
savePlayHistory(videoTitle)
|
||||||
|
|
||||||
lifecycleScope.launch {
|
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) {
|
if (directUrl != null) {
|
||||||
controlPanel.visibility = View.GONE
|
controlPanel.visibility = View.GONE
|
||||||
playWithExoPlayer(directUrl)
|
playWithExoPlayer(directUrl)
|
||||||
|
|||||||
Reference in New Issue
Block a user