File tree Expand file tree Collapse file tree
app/shared/src/main/kotlin/dev/aaa1115910/bv/viewmodel
player/core/src/main/kotlin/dev/aaa1115910/bv/player/impl/exo Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -399,12 +399,15 @@ class VideoPlayerV3ViewModel(
399399 logger.fInfo { " Select audio: $audioItem " }
400400 addLogs(" 音频编码:${(Audio .fromCode(audioItem?.codecId ? : 0 ))?.getDisplayName(BVApp .context) ? : " 未知" } " )
401401
402- withContext(Dispatchers .Main ) {
403- currentVideoHeight = videoItem?.height ? : 0
404- currentVideoWidth = videoItem?.width ? : 0
405- logger.info { " Video url: $videoUrl " }
406- logger.info { " Audio url: $audioUrl " }
402+ currentVideoHeight = videoItem?.height ? : 0
403+ currentVideoWidth = videoItem?.width ? : 0
404+ logger.info { " Video url: $videoUrl " }
405+ logger.info { " Audio url: $audioUrl " }
406+ // 将 playUrl 移到 IO 线程,避免主线程阻塞
407+ withContext(Dispatchers .IO ) {
407408 videoPlayer!! .playUrl(videoUrl, audioUrl)
409+ }
410+ withContext(Dispatchers .Main ) {
408411 videoPlayer!! .prepare()
409412 showBuffering = true
410413 }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import dev.aaa1115910.bv.player.AbstractVideoPlayer
1818import dev.aaa1115910.bv.player.OkHttpUtil
1919import dev.aaa1115910.bv.player.VideoPlayerOptions
2020import dev.aaa1115910.bv.util.formatHourMinSec
21+ import java.util.concurrent.TimeUnit
2122
2223@OptIn(UnstableApi ::class )
2324class ExoMediaPlayer (
@@ -28,11 +29,15 @@ class ExoMediaPlayer(
2829 protected var mMediaSource: MediaSource ? = null
2930
3031 @OptIn(UnstableApi ::class )
31- private val dataSourceFactory =
32- OkHttpDataSource .Factory (OkHttpUtil .generateCustomSslOkHttpClient(context)).apply {
33- options.userAgent?.let { setUserAgent(it) }
34- options.referer?.let { setDefaultRequestProperties(mapOf (" referer" to it)) }
35- }
32+ private val dataSourceFactory = OkHttpDataSource .Factory (
33+ OkHttpUtil .generateCustomSslOkHttpClient(context).newBuilder()
34+ .connectTimeout(15 , TimeUnit .SECONDS )
35+ .readTimeout(15 , TimeUnit .SECONDS )
36+ .build()
37+ ).apply {
38+ options.userAgent?.let { setUserAgent(it) }
39+ options.referer?.let { setDefaultRequestProperties(mapOf (" referer" to it)) }
40+ }
3641
3742 init {
3843 initPlayer()
You can’t perform that action at this time.
0 commit comments