-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
默认的数据源所用的http客户端很多时候会被cf拦截,即使使用相同的请求头,指纹也有所区别,更换为okhttp可解决。
例如:
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(OkHttpHeaderInterceptor(headers))
.build()
val httpDataSourceFactory = OkHttpDataSource.Factory(okHttpClient)
val cacheDataSourceFactory = CacheDataSource.Factory()
.setCache(cache)
.setUpstreamDataSourceFactory(httpDataSourceFactory)
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
val mediaSourceFactory = ProgressiveMediaSource.Factory(cacheDataSourceFactory)现有API没办法做到这一点,需要修改ExoPlayerMediampPlayer的构造函数,增加一个MediaSource.Factory,然后在setDataImpl使用。
override suspend fun setDataImpl(data: MediaData): ExoPlayerData = when (data) {
is UriMediaData -> {
ExoPlayerData(
data,
releaseResource = {
data.close()
},
setMedia = {
val item = MediaItem.Builder().apply {
setUri(data.uri)
setSubtitleConfigurations(
data.extraFiles.subtitles.map {
MediaItem.SubtitleConfiguration.Builder(
it.uri.toUri(),
).apply {
it.label?.let { label -> setLabel(label) }
it.mimeType?.let { mimeType -> setMimeType(mimeType) }
it.language?.let { language -> setLanguage(language) }
}.build()
},
)
}.build()
withContext(Dispatchers.Main.immediate) {
exoPlayer.setMediaSource(mediaSourceFactory.createMediaSource(item))
}
},
)
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels