Search in sources :

Example 11 with SimpleCache

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();
}
Also used : DatabaseProvider(com.google.android.exoplayer2.database.DatabaseProvider) ExoDatabaseProvider(com.google.android.exoplayer2.database.ExoDatabaseProvider) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) ExoDatabaseProvider(com.google.android.exoplayer2.database.ExoDatabaseProvider) File(java.io.File)

Example 12 with SimpleCache

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);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) CacheDataSourceFactory(com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) Uri(android.net.Uri) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) CacheDataSourceFactory(com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) File(java.io.File) Cache(com.google.android.exoplayer2.upstream.cache.Cache) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache)

Example 13 with SimpleCache

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();
}
Also used : Context(android.content.Context) DefaultDownloadIndex(com.google.android.exoplayer2.offline.DefaultDownloadIndex) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) File(java.io.File) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Before(org.junit.Before)

Example 14 with SimpleCache

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);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) File(java.io.File)

Example 15 with SimpleCache

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);
}
Also used : SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) StandaloneDatabaseProvider(com.google.android.exoplayer2.database.StandaloneDatabaseProvider) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Before(org.junit.Before)

Aggregations

SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)11 File (java.io.File)8 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)7 Before (org.junit.Before)7 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)5 DataSource (com.google.android.exoplayer2.upstream.DataSource)4 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)4 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)3 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)3 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)3 Context (android.content.Context)2 DatabaseProvider (com.google.android.exoplayer2.database.DatabaseProvider)2 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 StreamKey (com.google.android.exoplayer2.offline.StreamKey)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2 DefaultHttpDataSource (com.google.android.exoplayer2.upstream.DefaultHttpDataSource)2 Cache (com.google.android.exoplayer2.upstream.cache.Cache)2 CacheDataSourceFactory (com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory)2 Notification (android.app.Notification)1