use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project Slide by ccrama.
the class Reddit method onCreate.
@Override
public void onCreate() {
super.onCreate();
mApplication = this;
// LeakCanary.install(this);
if (ProcessPhoenix.isPhoenixProcess(this)) {
return;
}
final File dir;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && getExternalCacheDir() != null) {
dir = new File(getExternalCacheDir() + File.separator + "video-cache");
} else {
dir = new File(getCacheDir() + File.separator + "video-cache");
}
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(256 * 1024 * 1024);
DatabaseProvider databaseProvider = new ExoDatabaseProvider(getAppContext());
// 256MB
videoCache = new SimpleCache(dir, evictor, databaseProvider);
UpgradeUtil.upgrade(getApplicationContext());
doMainStuff();
}
use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project react-native-track-player by react-native-kit.
the class ExoPlayback method load.
@Override
public void load(Track track, Promise callback) {
loadCallback = callback;
Uri url = track.url;
String userAgent = Util.getUserAgent(context, "react-native-track-player");
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, null, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
DataSource.Factory factory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
MediaSource source;
if (cacheMaxSize > 0 && !track.urlLocal) {
File cacheDir = new File(context.getCacheDir(), "TrackPlayer");
Cache cache = new SimpleCache(cacheDir, new LeastRecentlyUsedCacheEvictor(cacheMaxSize));
factory = new CacheDataSourceFactory(cache, factory, 0, cacheMaxSize);
}
if (track.type == TrackType.DASH) {
source = new DashMediaSource(url, factory, new DefaultDashChunkSource.Factory(factory), null, null);
} else if (track.type == TrackType.HLS) {
source = new HlsMediaSource(url, factory, null, null);
} else if (track.type == TrackType.SMOOTH_STREAMING) {
source = new SsMediaSource(url, factory, new DefaultSsChunkSource.Factory(factory), null, null);
} else {
source = new ExtractorMediaSource(url, factory, new DefaultExtractorsFactory(), null, null);
}
player.prepare(source);
}
use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.
the class DownloadManagerDashTest method setUp.
@Before
public void setUp() throws Exception {
ShadowLog.stream = System.out;
testThread = new DummyMainThread();
Context context = ApplicationProvider.getApplicationContext();
tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
File cacheFolder = new File(tempFolder, "cache");
cacheFolder.mkdir();
cache = new SimpleCache(cacheFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
MockitoAnnotations.initMocks(this);
fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
fakeStreamKey1 = new StreamKey(0, 0, 0);
fakeStreamKey2 = new StreamKey(0, 1, 0);
downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
createDownloadManager();
}
use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.
the class CacheDataSourceContractTest method createDataSource.
@Override
protected DataSource createDataSource() throws IOException {
File tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
SimpleCache cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
upstreamDataSource = new FakeDataSource(fakeDataSet);
return new CacheDataSource(cache, upstreamDataSource);
}
use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.
the class DashDownloadTest method setUp.
@Before
public void setUp() throws Exception {
testRunner = new DashTestRunner(TAG, testRule.getActivity()).setManifestUrl(DashTestData.H264_MANIFEST).setFullPlaybackNoSeeking(true).setCanIncludeAdditionalVideoFormats(false).setAudioVideoFormats(DashTestData.AAC_AUDIO_REPRESENTATION_ID, DashTestData.H264_CDD_FIXED);
tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest");
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), new StandaloneDatabaseProvider(testRule.getActivity()));
httpDataSourceFactory = new DefaultHttpDataSource.Factory();
offlineDataSourceFactory = new CacheDataSource.Factory().setCache(cache);
}
Aggregations