I have this Error " java.lang.IllegalStateException: Another SimpleCache instance uses the folder:" i am working with SimpleExoPlayer and this error show when i try to open the video for second time how to close or delete the previous simplecache ? and this is my code :
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);
You need to make your cache class Singleton
to make sure you have one instance of SimpleCache
across all your application:
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;
}
}
And use it in your code like:
DataSource.Factory dataSourceFactory = new CacheDataSourceFactory(VideoCache.getInstance(this), new DefaultDataSourceFactory(this, "seyed"));
Making the cache
object singleton does not necessarily solve the problem because the cache
can still be locked due to a previous audio player call. When this happens, the IllegalStateException
will still be thrown.
To solve this, you need to release the cache
when releasing the player, i.e. put this in the overridden release
method of the player:
cache.release();
cache = null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With