Android 将ExoPlayer从2.11.8升级到2.12.1并更换不推荐的组件后,我可以';我不能播放任何视频
我最近将Android 将ExoPlayer从2.11.8升级到2.12.1并更换不推荐的组件后,我可以';我不能播放任何视频,android,exoplayer,exoplayer2.x,Android,Exoplayer,Exoplayer2.x,我最近将com.google.android.exoplayer:exoplayer-core从2.11.8版升级到了2.12.1版。 在以下代码段中,版本2.12.1不推荐使用某些组件 cacheEvictor = LeastRecentlyUsedCacheEvictor(CACHE_SIZE_MAX) databaseProvider = ExoDatabaseProvider(context) cache = SimpleCache(Fil
com.google.android.exoplayer:exoplayer-core
从2.11.8版升级到了2.12.1版。在以下代码段中,版本2.12.1不推荐使用某些组件
cacheEvictor = LeastRecentlyUsedCacheEvictor(CACHE_SIZE_MAX)
databaseProvider = ExoDatabaseProvider(context)
cache = SimpleCache(File(context.cacheDir, CACHE_DIR),
cacheEvictor, databaseProvider)
upstreamFactory = DefaultDataSourceFactory(context, USER_AGENT)
// CacheDataSourceFactory class is deprecated
cacheFactory = CacheDataSourceFactory(cache, upstreamFactory,
CacheDataSource.FLAG_BLOCK_ON_CACHE or
CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
mediaSourceFactory = ProgressiveMediaSource.Factory(cacheFactory)
[...]
val url: Uri
val player: SimpleExoPlayer
[...]
// createMediaSource method is deprecated
val mediaSource = mediaSourceFactory.createMediaSource(uri)
// prepare method is deprecated
player.prepare(mediaSource, true, true)
因此,我用最新的组件替换了不推荐使用的组件
cacheEvictor = LeastRecentlyUsedCacheEvictor(CACHE_SIZE_MAX)
databaseProvider = ExoDatabaseProvider(context)
cache = SimpleCache(File(context.cacheDir, CACHE_DIR),
cacheEvictor, databaseProvider)
upstreamFactory = DefaultDataSourceFactory(context, USER_AGENT)
cacheFactory = CacheDataSource.Factory().apply {
setCache(this@VideoPlayer.cache)
setUpstreamDataSourceFactory(upstreamFactory)
setFlags(CacheDataSource.FLAG_BLOCK_ON_CACHE or
CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
}
mediaSourceFactory = ProgressiveMediaSource.Factory(cacheFactory)
[...]
val url: Uri
val player: SimpleExoPlayer
[...]
val mediaItem = MediaItem.fromUri(uri)
val mediaSource = mediaSourceFactory.createMediaSource(mediaItem)
player.setMediaSource(mediaSource, true)
// The following missed
player.prepare(mediaSource)
更新后,播放器是黑色的,我无法播放任何视频(在Logcat中没有任何有用的内容)。
我回到了不推荐使用的组件(仍然是2.12.1版),现在我可以播放每一个视频了
我想我在更换不推荐使用的组件时把事情弄糟了。有人能帮我吗?我刚刚修复了答案中的代码:我忘记了上一个
播放器。prepare()
现在它工作得很好