We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
插件能力, 播放器
如题, 以下是代码参考
fun getMediaSourceFactory(playerInfo: PlayerInfo): MediaSource.Factory { val httpDataSourceFactory = DefaultHttpDataSource.Factory() .setDefaultRequestProperties(playerInfo.header ?: emptyMap()) val dataSourceFactory = DefaultDataSource.Factory(APP, httpDataSourceFactory) val streamDataSinkFactory = CacheDataSink.Factory().setCache(normalCache) val normalCacheDataSourceFactory = CacheDataSource.Factory() .setCache(normalCache) .setUpstreamDataSourceFactory(dataSourceFactory) .setCacheWriteDataSinkFactory(streamDataSinkFactory) .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) return when (playerInfo.decodeType) { C.CONTENT_TYPE_DASH -> DashMediaSource.Factory(normalCacheDataSourceFactory) C.CONTENT_TYPE_HLS -> { // Use custom DataSource.Factory to modify M3U8 content val customHlsDataSourceFactory = CustomDataSourceFactory( normalCacheDataSourceFactory, playerInfo.replaces ) HlsMediaSource.Factory(customHlsDataSourceFactory) } else -> ProgressiveMediaSource.Factory(normalCacheDataSourceFactory) } } // Custom DataSource.Factory that modifies M3U8 content class CustomDataSourceFactory( private val upstreamFactory: DataSource.Factory, private val replaces: List> ) : DataSource.Factory { override fun createDataSource(): DataSource { return object : DataSource { private var upstream: DataSource = upstreamFactory.createDataSource() override fun open(dataSpec: DataSpec): Long { return upstream.open(dataSpec) } override fun read(buffer: ByteArray, offset: Int, readLength: Int): Int { val result = upstream.read(buffer, offset, readLength) if (result == C.RESULT_END_OF_INPUT) { val m3u8Content = String(buffer, StandardCharsets.UTF_8) val modifiedM3u8Content = modifyM3u8Content(m3u8Content, replaces) val byteArrayInputStream: InputStream = ByteArrayInputStream( modifiedM3u8Content.toByteArray(StandardCharsets.UTF_8) ) return byteArrayInputStream.read(buffer, offset, readLength) } return result } override fun getUri(): Uri? = upstream.uri override fun close() { upstream.close() } } } // Function to modify M3U8 content using the list of regex replacements private fun modifyM3u8Content(content: String, replaces: List>): String { var modifiedContent = content for ((regex, replacement) in replaces) { modifiedContent = regex.replace(modifiedContent, replacement) } return modifiedContent } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
功能范围
插件能力, 播放器
功能描述
如题, 以下是代码参考
The text was updated successfully, but these errors were encountered: