From 6457ed36cbe285ad7f0a45d24206cab1013e07d9 Mon Sep 17 00:00:00 2001 From: Jorge Antonio Diaz-Benito Soriano Date: Thu, 8 Aug 2024 16:26:23 +0200 Subject: [PATCH] Ignore all ExoPlayer caches on error I suspect this can cause issues if the remote item is taken down due to a label request. --- .../datasource/CacheKeyAesCipherDataSourceFactoryFactory.kt | 3 ++- .../offline/OfflinePlayDrmDataSourceFactoryHelper.kt | 1 + .../player/playbackengine/player/di/MediaSourcererModule.kt | 1 + .../offline/OfflinePlayDrmDataSourceFactoryHelperTest.kt | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/datasource/CacheKeyAesCipherDataSourceFactoryFactory.kt b/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/datasource/CacheKeyAesCipherDataSourceFactoryFactory.kt index f6ab215c..fd260a48 100644 --- a/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/datasource/CacheKeyAesCipherDataSourceFactoryFactory.kt +++ b/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/datasource/CacheKeyAesCipherDataSourceFactoryFactory.kt @@ -15,6 +15,7 @@ internal class CacheKeyAesCipherDataSourceFactoryFactory( fun create(cache: Cache) = CacheKeyAesCipherDataSourceFactory( cacheKeyFactory, encryption!!.secretKey, - cacheDataSourceFactory.setCache(cache), + cacheDataSourceFactory.setCache(cache) + .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR), ) } diff --git a/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelper.kt b/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelper.kt index 07ad2449..6bba727e 100644 --- a/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelper.kt +++ b/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelper.kt @@ -17,4 +17,5 @@ internal class OfflinePlayDrmDataSourceFactoryHelper( ) : OfflineDataSourceFactoryHelper(offlineCacheProvider) { override fun create(cache: Cache) = cacheDataSourceFactory.setCache(cache) + .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) } diff --git a/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/player/di/MediaSourcererModule.kt b/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/player/di/MediaSourcererModule.kt index 93ffd1fb..68ac47bd 100644 --- a/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/player/di/MediaSourcererModule.kt +++ b/player/playback-engine/src/main/kotlin/com/tidal/sdk/player/playbackengine/player/di/MediaSourcererModule.kt @@ -158,6 +158,7 @@ internal object MediaSourcererModule { .setUpstreamDataSourceFactory(okHttpDataSourceFactory) .setCacheReadDataSourceFactory(fileDataSourceFactory) .setCacheWriteDataSinkFactory(cacheDataSinkFactory) + .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) } @Provides diff --git a/player/playback-engine/src/test/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelperTest.kt b/player/playback-engine/src/test/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelperTest.kt index e867f683..3eebc2b0 100644 --- a/player/playback-engine/src/test/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelperTest.kt +++ b/player/playback-engine/src/test/kotlin/com/tidal/sdk/player/playbackengine/offline/OfflinePlayDrmDataSourceFactoryHelperTest.kt @@ -31,11 +31,14 @@ internal class OfflinePlayDrmDataSourceFactoryHelperTest { fun create() { val cache = mock() whenever(cacheDataSourceFactory.setCache(cache)).thenReturn(cacheDataSourceFactory) + whenever(cacheDataSourceFactory.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)) + .thenReturn(cacheDataSourceFactory) val actualDataSourceFactory = offlinePlayDrmDataSourceFactoryHelper.create(cache) assertThat(actualDataSourceFactory).isSameAs(cacheDataSourceFactory) verify(cacheDataSourceFactory).setCache(cache) + verify(cacheDataSourceFactory).setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) verifyNoMoreInteractions( cache, cacheDataSourceFactory,