java - java.lang.IllegalStateException:另一个 SimpleCache 实例使用该文件夹:
问题描述
我有这个错误 “java.lang.IllegalStateException:另一个 SimpleCache 实例使用文件夹:” 我正在使用 SimpleExoPlayer,当我第二次尝试打开视频时,这个错误显示如何关闭或删除以前的 simplecache?这是我的代码:
SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.video_view);
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(new DefaultBandwidthMeter.Builder().build()));
SimpleCache downloadCache = new SimpleCache(new File(getCacheDir(), "exoCache"), new NoOpCacheEvictor());
String uri = "http://dash.akamaized.net/akamai/bbb/bbb_1280x720_60fps_6000k.mp4";
DataSource.Factory dataSourceFactory = new CacheDataSourceFactory(downloadCache, new DefaultDataSourceFactory(this, "seyed"));
MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(uri));
player.prepare(mediaSource);
simpleExoPlayerView.setPlayer(player);
player.setPlayWhenReady(true);
解决方案
您需要创建缓存类Singleton
以确保您SimpleCache
在所有应用程序中都有一个实例:
public class VideoCache {
private static SimpleCache sDownloadCache;
public static SimpleCache getInstance(Context context) {
if (sDownloadCache == null) sDownloadCache = new SimpleCache(new File(context.getCacheDir(), "exoCache"), new NoOpCacheEvictor(), new ExoDatabaseProvider(context));
return sDownloadCache;
}
}
并在您的代码中使用它,例如:
DataSource.Factory dataSourceFactory = new CacheDataSourceFactory(VideoCache.getInstance(this), new DefaultDataSourceFactory(this, "seyed"));
推荐阅读
- python - 为什么这个查找无序列表的最小值和最大值的函数在某些情况下不起作用?
- version-control - VCS 窗口中缺少“忽略”选项
- angular-material-stepper - 如何在单击“下一步”时拨打电话并决定是否继续使用 CDKStepper?
- python - 在列中搜索 str 并创建新的项目列表
- ruby-on-rails - 如何根据数据库中的记录创建具有最少位数的 url 链接缩短 slug
- python-3.x - 从列表中删除一定百分比的元素,同时保留列表的结构完整性
- ant - ant如何检查驱动器D是否存在
- python - 在熊猫中编写文件比较
- c - **(x+i) 和 *(*x+i) 之间的区别
- c# - 无法将 Ioptions 传递给静态扩展方法或预热单例