I've recently upgraded com.google.android.exoplayer:exoplayer-core
from version 2.11.8 to version 2.12.1.
Some components are deprecated by version 2.12.1 in the following code snippet.
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)
Thus I replaced the deprecated components by the newest ones.
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)
After the updates, the player was black and I could not play any video (nothing usefull in Logcat). I've returned to the deprecated components (still with version 2.12.1) and now I can play every video.
I think I messed up something when in replacing the deprecated components.
Can anyone help me, please?