3
3
import android .content .Context ;
4
4
import android .util .Log ;
5
5
6
- import androidx .annotation .NonNull ;
7
-
8
- import com .google .android .exoplayer2 .database .ExoDatabaseProvider ;
6
+ import com .google .android .exoplayer2 .database .StandaloneDatabaseProvider ;
9
7
import com .google .android .exoplayer2 .upstream .DataSource ;
10
8
import com .google .android .exoplayer2 .upstream .DefaultDataSource ;
11
- import com .google .android .exoplayer2 .upstream .DefaultDataSourceFactory ;
9
+ import com .google .android .exoplayer2 .upstream .DefaultHttpDataSource ;
12
10
import com .google .android .exoplayer2 .upstream .FileDataSource ;
13
11
import com .google .android .exoplayer2 .upstream .TransferListener ;
14
12
import com .google .android .exoplayer2 .upstream .cache .CacheDataSink ;
18
16
19
17
import java .io .File ;
20
18
19
+ import androidx .annotation .NonNull ;
20
+
21
21
/* package-private */ class CacheFactory implements DataSource .Factory {
22
22
private static final String TAG = "CacheFactory" ;
23
23
24
24
private static final String CACHE_FOLDER_NAME = "exoplayer" ;
25
25
private static final int CACHE_FLAGS = CacheDataSource .FLAG_BLOCK_ON_CACHE
26
26
| CacheDataSource .FLAG_IGNORE_CACHE_ON_ERROR ;
27
27
28
- private final DefaultDataSourceFactory dataSourceFactory ;
28
+ private final DataSource . Factory dataSourceFactory ;
29
29
private final File cacheDir ;
30
30
private final long maxFileSize ;
31
31
@@ -49,7 +49,9 @@ private CacheFactory(@NonNull final Context context,
49
49
final long maxFileSize ) {
50
50
this .maxFileSize = maxFileSize ;
51
51
52
- dataSourceFactory = new DefaultDataSourceFactory (context , userAgent , transferListener );
52
+ dataSourceFactory = new DefaultDataSource
53
+ .Factory (context , new DefaultHttpDataSource .Factory ().setUserAgent (userAgent ))
54
+ .setTransferListener (transferListener );
53
55
cacheDir = new File (context .getExternalCacheDir (), CACHE_FOLDER_NAME );
54
56
if (!cacheDir .exists ()) {
55
57
//noinspection ResultOfMethodCallIgnored
@@ -59,7 +61,7 @@ private CacheFactory(@NonNull final Context context,
59
61
if (cache == null ) {
60
62
final LeastRecentlyUsedCacheEvictor evictor
61
63
= new LeastRecentlyUsedCacheEvictor (maxCacheSize );
62
- cache = new SimpleCache (cacheDir , evictor , new ExoDatabaseProvider (context ));
64
+ cache = new SimpleCache (cacheDir , evictor , new StandaloneDatabaseProvider (context ));
63
65
}
64
66
}
65
67
@@ -68,7 +70,7 @@ private CacheFactory(@NonNull final Context context,
68
70
public DataSource createDataSource () {
69
71
Log .d (TAG , "initExoPlayerCache: cacheDir = " + cacheDir .getAbsolutePath ());
70
72
71
- final DefaultDataSource dataSource = dataSourceFactory .createDataSource ();
73
+ final DataSource dataSource = dataSourceFactory .createDataSource ();
72
74
final FileDataSource fileSource = new FileDataSource ();
73
75
final CacheDataSink dataSink = new CacheDataSink (cache , maxFileSize );
74
76
0 commit comments