Search in sources :

Example 1 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class CacheDataSourceTest method createCacheDataSource.

private CacheDataSource createCacheDataSource(boolean setReadException, boolean simulateUnknownLength, @CacheDataSource.Flags int flags, CacheDataSink cacheWriteDataSink) {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    if (setReadException) {
        builder.appendReadError(new IOException("Shouldn't read from upstream"));
    }
    FakeDataSource upstream = builder.setSimulateUnknownLength(simulateUnknownLength).appendReadData(TEST_DATA).build();
    return new CacheDataSource(simpleCache, upstream, new FileDataSource(), cacheWriteDataSink, flags, null);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) IOException(java.io.IOException)

Example 2 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project Slide by ccrama.

the class SlideVideoControls method createDataSource.

@Override
public DataSource createDataSource() {
    LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
    SimpleCache simpleCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor);
    return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(), new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize), CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);
}
Also used : CacheDataSink(com.google.android.exoplayer2.upstream.cache.CacheDataSink) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) File(java.io.File)

Example 3 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project AndroidAudioExample by SergeyVinyar.

the class PlayerService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);
        AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN).setOnAudioFocusChangeListener(audioFocusChangeListener).setAcceptsDelayedFocusGain(false).setWillPauseWhenDucked(true).setAudioAttributes(audioAttributes).build();
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mediaSession = new MediaSessionCompat(this, "PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);
    Context appContext = getApplicationContext();
    Intent activityIntent = new Intent(appContext, MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));
    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null);
    // 100 Mb max
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100));
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
Also used : Context(android.content.Context) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) OkHttpClient(okhttp3.OkHttpClient) NotificationManager(android.app.NotificationManager) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) AudioAttributes(android.media.AudioAttributes) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) DataSource(com.google.android.exoplayer2.upstream.DataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) NotificationChannel(android.app.NotificationChannel) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) CacheDataSourceFactory(com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) OkHttpDataSourceFactory(com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) File(java.io.File) Cache(com.google.android.exoplayer2.upstream.cache.Cache) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache)

Example 4 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class DemoUtil method getDownloadCache.

private static synchronized Cache getDownloadCache(Context context) {
    if (downloadCache == null) {
        File downloadContentDirectory = new File(getDownloadDirectory(context), DOWNLOAD_CONTENT_DIRECTORY);
        downloadCache = new SimpleCache(downloadContentDirectory, new NoOpCacheEvictor(), getDatabaseProvider(context));
    }
    return downloadCache;
}
Also used : SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) File(java.io.File)

Example 5 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class ProgressiveDownloaderTest method createDownloadCache.

@Before
public void createDownloadCache() throws Exception {
    testDir = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ProgressiveDownloaderTest");
    assertThat(testDir.delete()).isTrue();
    assertThat(testDir.mkdirs()).isTrue();
    DatabaseProvider databaseProvider = TestUtil.getInMemoryDatabaseProvider();
    downloadCache = new SimpleCache(testDir, new NoOpCacheEvictor(), databaseProvider);
}
Also used : DatabaseProvider(com.google.android.exoplayer2.database.DatabaseProvider) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) Before(org.junit.Before)

Aggregations

SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)10 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)7 File (java.io.File)7 Before (org.junit.Before)7 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)5 DataSource (com.google.android.exoplayer2.upstream.DataSource)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 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)3 Context (android.content.Context)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 NotificationChannel (android.app.NotificationChannel)1