【问题标题】:How to use SupportSQLiteDatabase with exoplayer's SimpleCache?如何将 SupportSQLiteDatabase 与 exoplayer 的 SimpleCache 一起使用?
【发布时间】:2021-06-27 07:44:42
【问题描述】:

我正在尝试将房间与 exoplayer 一起使用,但SupportSQLDatabase 是一个界面。

这是我的代码。

            val evictor = LeastRecentlyUsedCacheEvictor(maxCacheSize)
            val simpleCache = SimpleCache(File(context.cacheDir, "media"), evictor, object : DatabaseProvider{
                override fun getWritableDatabase(): SQLiteDatabase {
                    return  RoomDatabase.openHelper.writableDatabase <- returns SupportSQLDatabase
                                                    ^^^^^^^^^^^^^^^^
                }
    
                override fun getReadableDatabase(): SQLiteDatabase {
                    return  RoomDatabase.openHelper.readableDatabase
                                                    ^^^^^^^^^^^^^^^^
                }
    
            })
            return CacheDataSource(
                simpleCache,
                defaultDatasourceFactory.createDataSource(),
                FileDataSource(),
                CacheDataSink(simpleCache, maxFileSize),
                CacheDataSource.FLAG_BLOCK_ON_CACHE or CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR,
                null
            )

不推荐使用不带 DatabaseProvider 的 SimpleCache

SimpleCache 有什么替代品与房间兼容吗?

【问题讨论】:

    标签: android kotlin android-sqlite android-room exoplayer2.x


    【解决方案1】:
    val simpleCache = SimpleCache(File(context.cacheDir, "media"), evictor, ExoDatabaseProvider(context))
    

    这似乎有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 2016-01-26
      • 1970-01-01
      相关资源
      最近更新 更多