forked from RalfNieuwenhuizen/react-native-video
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoCache.java
More file actions
52 lines (40 loc) · 1.21 KB
/
VideoCache.java
File metadata and controls
52 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.brentvatne.exoplayer;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
public class VideoCache {
private static volatile VideoCache instance;
private SimpleCache cache;
private VideoCache() {
if (instance != null) {
throw new RuntimeException("Use getInstance()");
}
}
public void setSimpleCache(SimpleCache cache) {
this.cache = cache;
}
public SimpleCache getSimpleCache() {
if (this.cache == null) {
throw new RuntimeException("Tried to access video cache but no cache is set");
}
return this.cache;
}
public boolean hasSimpleCache() {
return this.cache != null;
}
public void resetSimpleCache() {
if (hasSimpleCache()) {
this.cache.release();
this.cache = null;
} else {
throw new RuntimeException("Resetting video cache but no cache is set!");
}
return;
}
public static VideoCache getInstance() {
if (instance == null) {
synchronized (VideoCache.class) {
if (instance == null) instance = new VideoCache();
}
}
return instance;
}
}