com.google.android.exoplayer2.upstream.cache.Cache Java Examples

The following examples show how to use com.google.android.exoplayer2.upstream.cache.Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExoSourceManager.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 根据缓存块判断是否缓存成功
 *
 * @param cache
 */
private static boolean resolveCacheState(Cache cache, String url) {
    boolean isCache = true;
    if (!TextUtils.isEmpty(url)) {
        String key = CacheUtil.generateKey(Uri.parse(url));
        if (!TextUtils.isEmpty(key)) {
            NavigableSet<CacheSpan> cachedSpans = cache.getCachedSpans(key);
            if (cachedSpans.size() == 0) {
                isCache = false;
            } else {
                long contentLength = cache.getContentMetadata(key).get(ContentMetadata.KEY_CONTENT_LENGTH, C.LENGTH_UNSET);
                long currentLength = 0;
                for (CacheSpan cachedSpan : cachedSpans) {
                    currentLength += cache.getCachedLength(key, cachedSpan.position, cachedSpan.length);
                }
                isCache = currentLength >= contentLength;
            }
        } else {
            isCache = false;
        }
    }
    return isCache;
}
 
Example #2
Source File: ExoSourceManager.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * Cache需要release之后才能clear
 *
 * @param context
 * @param cacheDir
 * @param url
 */
public static void clearCache(Context context, File cacheDir, String url) {
    try {
        Cache cache = getCacheSingleInstance(context, cacheDir);
        if (!TextUtils.isEmpty(url)) {
            if (cache != null) {
                CacheUtil.remove(cache, CacheUtil.generateKey(Uri.parse(url)));
            }
        } else {
            if (cache != null) {
                for (String key : cache.getKeys()) {
                    CacheUtil.remove(cache, key);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #3
Source File: DownloaderConstructorHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 */
public DownloaderConstructorHelper(Cache cache, DataSource.Factory upstreamFactory) {
  this(
      cache,
      upstreamFactory,
      /* cacheReadDataSourceFactory= */ null,
      /* cacheWriteDataSinkFactory= */ null,
      /* priorityTaskManager= */ null);
}
 
Example #4
Source File: DownloaderConstructorHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 * @param cacheReadDataSourceFactory A {@link DataSource.Factory} for creating {@link DataSource}s
 *     for reading data from the cache. If null then a {@link FileDataSource.Factory} will be
 *     used.
 * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for creating {@link DataSource}s
 *     for writing data to the cache. If null then a {@link CacheDataSinkFactory} will be used.
 * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null,
 *     downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst
 *     downloading.
 */
public DownloaderConstructorHelper(
    Cache cache,
    DataSource.Factory upstreamFactory,
    @Nullable DataSource.Factory cacheReadDataSourceFactory,
    @Nullable DataSink.Factory cacheWriteDataSinkFactory,
    @Nullable PriorityTaskManager priorityTaskManager) {
  this(
      cache,
      upstreamFactory,
      cacheReadDataSourceFactory,
      cacheWriteDataSinkFactory,
      priorityTaskManager,
      /* cacheKeyFactory= */ null);
}
 
Example #5
Source File: DownloaderConstructorHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 * @param cacheReadDataSourceFactory A {@link DataSource.Factory} for creating {@link DataSource}s
 *     for reading data from the cache. If null then a {@link FileDataSourceFactory} will be used.
 * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for creating {@link DataSource}s
 *     for writing data to the cache. If null then a {@link CacheDataSinkFactory} will be used.
 * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null,
 *     downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst
 *     downloading.
 */
public DownloaderConstructorHelper(
    Cache cache,
    DataSource.Factory upstreamFactory,
    @Nullable DataSource.Factory cacheReadDataSourceFactory,
    @Nullable DataSink.Factory cacheWriteDataSinkFactory,
    @Nullable PriorityTaskManager priorityTaskManager) {
  this(
      cache,
      upstreamFactory,
      cacheReadDataSourceFactory,
      cacheWriteDataSinkFactory,
      priorityTaskManager,
      /* cacheKeyFactory= */ null);
}
 
Example #6
Source File: DownloadManager.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link DownloadManager}.
 *
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link DataSource.Factory} for creating data sources for
 *     downloading upstream data.
 * @param actionSaveFile File to save active actions.
 * @param deserializers Used to deserialize {@link DownloadAction}s. If empty, {@link
 *     DownloadAction#getDefaultDeserializers()} is used instead.
 */
public DownloadManager(
    Cache cache,
    DataSource.Factory upstreamDataSourceFactory,
    File actionSaveFile,
    Deserializer... deserializers) {
  this(
      new DownloaderConstructorHelper(cache, upstreamDataSourceFactory),
      actionSaveFile,
      deserializers);
}
 
Example #7
Source File: DownloaderConstructorHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 */
public DownloaderConstructorHelper(Cache cache, DataSource.Factory upstreamFactory) {
  this(
      cache,
      upstreamFactory,
      /* cacheReadDataSourceFactory= */ null,
      /* cacheWriteDataSinkFactory= */ null,
      /* priorityTaskManager= */ null);
}
 
Example #8
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link Factory} for downloading data.
 * @param cacheReadDataSourceFactory A {@link Factory} for reading data from the cache. If null
 *     then standard {@link FileDataSource} instances will be used.
 * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for writing data to the cache. If
 *     null then standard {@link CacheDataSink} instances will be used.
 * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null,
 *     downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst
 *     downloading.
 */
public DownloaderConstructorHelper(
    Cache cache,
    Factory upstreamDataSourceFactory,
    @Nullable Factory cacheReadDataSourceFactory,
    @Nullable DataSink.Factory cacheWriteDataSinkFactory,
    @Nullable PriorityTaskManager priorityTaskManager) {
  Assertions.checkNotNull(upstreamDataSourceFactory);
  this.cache = cache;
  this.upstreamDataSourceFactory = upstreamDataSourceFactory;
  this.cacheReadDataSourceFactory = cacheReadDataSourceFactory;
  this.cacheWriteDataSinkFactory = cacheWriteDataSinkFactory;
  this.priorityTaskManager = priorityTaskManager;
}
 
Example #9
Source File: DownloaderConstructorHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 * @param cacheReadDataSourceFactory A {@link DataSource.Factory} for creating {@link DataSource}s
 *     for reading data from the cache. If null then a {@link FileDataSourceFactory} will be used.
 * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for creating {@link DataSource}s
 *     for writing data to the cache. If null then a {@link CacheDataSinkFactory} will be used.
 * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null,
 *     downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst
 *     downloading.
 */
public DownloaderConstructorHelper(
    Cache cache,
    DataSource.Factory upstreamFactory,
    @Nullable DataSource.Factory cacheReadDataSourceFactory,
    @Nullable DataSink.Factory cacheWriteDataSinkFactory,
    @Nullable PriorityTaskManager priorityTaskManager) {
  this(
      cache,
      upstreamFactory,
      cacheReadDataSourceFactory,
      cacheWriteDataSinkFactory,
      priorityTaskManager,
      /* cacheKeyFactory= */ null);
}
 
Example #10
Source File: DownloadManager.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link DownloadManager}.
 *
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link DataSource.Factory} for creating data sources for
 *     downloading upstream data.
 * @param actionSaveFile File to save active actions.
 * @param deserializers Used to deserialize {@link DownloadAction}s. If empty, {@link
 *     DownloadAction#getDefaultDeserializers()} is used instead.
 */
public DownloadManager(
    Cache cache,
    DataSource.Factory upstreamDataSourceFactory,
    File actionSaveFile,
    Deserializer... deserializers) {
  this(
      new DownloaderConstructorHelper(cache, upstreamDataSourceFactory),
      actionSaveFile,
      deserializers);
}
 
Example #11
Source File: DownloaderConstructorHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 */
public DownloaderConstructorHelper(Cache cache, DataSource.Factory upstreamFactory) {
  this(
      cache,
      upstreamFactory,
      /* cacheReadDataSourceFactory= */ null,
      /* cacheWriteDataSinkFactory= */ null,
      /* priorityTaskManager= */ null);
}
 
Example #12
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link Factory} for downloading data.
 * @param cacheReadDataSourceFactory A {@link Factory} for reading data from the cache. If null
 *     then standard {@link FileDataSource} instances will be used.
 * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for writing data to the cache. If
 *     null then standard {@link CacheDataSink} instances will be used.
 * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null,
 *     downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst
 *     downloading.
 */
public DownloaderConstructorHelper(
    Cache cache,
    Factory upstreamDataSourceFactory,
    @Nullable Factory cacheReadDataSourceFactory,
    @Nullable DataSink.Factory cacheWriteDataSinkFactory,
    @Nullable PriorityTaskManager priorityTaskManager) {
  Assertions.checkNotNull(upstreamDataSourceFactory);
  this.cache = cache;
  this.upstreamDataSourceFactory = upstreamDataSourceFactory;
  this.cacheReadDataSourceFactory = cacheReadDataSourceFactory;
  this.cacheWriteDataSinkFactory = cacheWriteDataSinkFactory;
  this.priorityTaskManager = priorityTaskManager;
}
 
Example #13
Source File: ExoSourceManager.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 获取SourceFactory,是否带Cache
 */
private DataSource.Factory getDataSourceFactoryCache(Context context, boolean cacheEnable, boolean preview, File cacheDir, String uerAgent) {
    if (cacheEnable) {
        Cache cache = getCacheSingleInstance(context, cacheDir);
        if (cache != null) {
            isCached = resolveCacheState(cache, mDataSource);
            return new CacheDataSourceFactory(cache, getDataSourceFactory(context, preview, uerAgent), CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
        }
    }
    return getDataSourceFactory(context, preview, uerAgent);
}
 
Example #14
Source File: DownloaderConstructorHelper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the {@link Cache} instance. */
public Cache getCache() {
  return cache;
}
 
Example #15
Source File: DownloaderConstructorHelper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the {@link Cache} instance. */
public Cache getCache() {
  return cache;
}
 
Example #16
Source File: ExoPlayerErrorMapperTest.java    From no-player with Apache License 2.0 4 votes vote down vote up
@Parameterized.Parameters(name = "{0} with detail {1} is mapped from {2}")
public static Collection<Object[]> parameters() {
    return Arrays.asList(
            new Object[]{SOURCE, SAMPLE_QUEUE_MAPPING_ERROR, createSource(new SampleQueueMappingException("mimetype-sample"))},
            new Object[]{SOURCE, READING_LOCAL_FILE_ERROR, createSource(new FileDataSource.FileDataSourceException(new IOException()))},
            new Object[]{SOURCE, UNEXPECTED_LOADING_ERROR, createSource(new Loader.UnexpectedLoaderException(new Throwable()))},
            new Object[]{SOURCE, LIVE_STALE_MANIFEST_AND_NEW_MANIFEST_COULD_NOT_LOAD_ERROR, createSource(new DashManifestStaleException())},
            new Object[]{SOURCE, DOWNLOAD_ERROR, createSource(new DownloadException("download-exception"))},
            new Object[]{SOURCE, AD_LOAD_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForAd(new Exception()))},
            new Object[]{SOURCE, AD_GROUP_LOAD_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForAdGroup(new Exception(), 0))},
            new Object[]{SOURCE, ALL_ADS_LOAD_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForAllAds(new Exception()))},
            new Object[]{SOURCE, ADS_LOAD_UNEXPECTED_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForUnexpected(new RuntimeException()))},
            new Object[]{SOURCE, MERGING_MEDIA_SOURCE_CANNOT_MERGE_ITS_SOURCES, createSource(new MergingMediaSource.IllegalMergeException(MergingMediaSource.IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH))},
            new Object[]{SOURCE, CLIPPING_MEDIA_SOURCE_CANNOT_CLIP_WRAPPED_SOURCE_INVALID_PERIOD_COUNT, createSource(new ClippingMediaSource.IllegalClippingException(ClippingMediaSource.IllegalClippingException.REASON_INVALID_PERIOD_COUNT))},
            new Object[]{SOURCE, CLIPPING_MEDIA_SOURCE_CANNOT_CLIP_WRAPPED_SOURCE_NOT_SEEKABLE_TO_START, createSource(new ClippingMediaSource.IllegalClippingException(ClippingMediaSource.IllegalClippingException.REASON_NOT_SEEKABLE_TO_START))},
            new Object[]{SOURCE, CLIPPING_MEDIA_SOURCE_CANNOT_CLIP_WRAPPED_SOURCE_INVALID_PERIOD_COUNT, createSource(new ClippingMediaSource.IllegalClippingException(ClippingMediaSource.IllegalClippingException.REASON_INVALID_PERIOD_COUNT))},
            new Object[]{SOURCE, TASK_CANNOT_PROCEED_PRIORITY_TOO_LOW, createSource(new PriorityTaskManager.PriorityTooLowException(1, 2))},
            new Object[]{SOURCE, PARSING_MEDIA_DATA_OR_METADATA_ERROR, createSource(new ParserException())},
            new Object[]{SOURCE, CACHE_WRITING_DATA_ERROR, createSource(new Cache.CacheException("cache-exception"))},
            new Object[]{SOURCE, READ_LOCAL_ASSET_ERROR, createSource(new AssetDataSource.AssetDataSourceException(new IOException()))},
            new Object[]{SOURCE, DATA_POSITION_OUT_OF_RANGE_ERROR, createSource(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE))},

            new Object[]{CONNECTIVITY, HTTP_CANNOT_OPEN_ERROR, createSource(new HttpDataSource.HttpDataSourceException(new DataSpec(Uri.EMPTY, 0), HttpDataSource.HttpDataSourceException.TYPE_OPEN))},
            new Object[]{CONNECTIVITY, HTTP_CANNOT_READ_ERROR, createSource(new HttpDataSource.HttpDataSourceException(new DataSpec(Uri.EMPTY, 0), HttpDataSource.HttpDataSourceException.TYPE_READ))},
            new Object[]{CONNECTIVITY, HTTP_CANNOT_CLOSE_ERROR, createSource(new HttpDataSource.HttpDataSourceException(new DataSpec(Uri.EMPTY, 0), HttpDataSource.HttpDataSourceException.TYPE_CLOSE))},
            new Object[]{CONNECTIVITY, READ_CONTENT_URI_ERROR, createSource(new ContentDataSource.ContentDataSourceException(new IOException()))},
            new Object[]{CONNECTIVITY, READ_FROM_UDP_ERROR, createSource(new UdpDataSource.UdpDataSourceException(new IOException()))},

            new Object[]{RENDERER_DECODER, AUDIO_SINK_CONFIGURATION_ERROR, createRenderer(new AudioSink.ConfigurationException("configuration-exception"))},
            new Object[]{RENDERER_DECODER, AUDIO_SINK_INITIALISATION_ERROR, createRenderer(new AudioSink.InitializationException(0, 0, 0, 0))},
            new Object[]{RENDERER_DECODER, AUDIO_SINK_WRITE_ERROR, createRenderer(new AudioSink.WriteException(0))},
            new Object[]{RENDERER_DECODER, AUDIO_UNHANDLED_FORMAT_ERROR, createRenderer(new AudioProcessor.UnhandledFormatException(0, 0, 0))},
            new Object[]{RENDERER_DECODER, AUDIO_DECODER_ERROR, createRenderer(new AudioDecoderException("audio-decoder-exception"))},
            new Object[]{RENDERER_DECODER, INITIALISATION_ERROR, createRenderer(new MediaCodecRenderer.DecoderInitializationException(Format.createSampleFormat("id", "sample-mimety[e", 0), new Throwable(), true, 0))},
            new Object[]{RENDERER_DECODER, DECODING_SUBTITLE_ERROR, createRenderer(new SubtitleDecoderException("metadata-decoder-exception"))},

            new Object[]{DRM, UNSUPPORTED_DRM_SCHEME_ERROR, createRenderer(new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME))},
            new Object[]{DRM, DRM_INSTANTIATION_ERROR, createRenderer(new UnsupportedDrmException(UnsupportedDrmException.REASON_INSTANTIATION_ERROR))},
            new Object[]{DRM, DRM_SESSION_ERROR, createRenderer(new DrmSession.DrmSessionException(new Throwable()))},
            new Object[]{DRM, DRM_KEYS_EXPIRED_ERROR, createRenderer(new KeysExpiredException())},
            new Object[]{DRM, MEDIA_REQUIRES_DRM_SESSION_MANAGER_ERROR, createRenderer(new IllegalStateException())},

            new Object[]{CONTENT_DECRYPTION, FAIL_DECRYPT_DATA_DUE_NON_PLATFORM_COMPONENT_ERROR, createRenderer(new DecryptionException(0, "decryption-exception"))},

            new Object[]{UNEXPECTED, MULTIPLE_RENDERER_MEDIA_CLOCK_ENABLED_ERROR, ExoPlaybackExceptionFactory.createForUnexpected(new IllegalStateException("Multiple renderer media clocks enabled."))},
            new Object[]{PlayerErrorType.UNKNOWN, DetailErrorType.UNKNOWN, ExoPlaybackExceptionFactory.createForUnexpected(new IllegalStateException("Any other exception"))}
            // DefaultAudioSink.InvalidAudioTrackTimestampException is private, cannot create
            // EGLSurfaceTexture.GlException is private, cannot create
            // PlaylistStuckException constructor is private, cannot create
            // PlaylistResetException constructor is private, cannot create
            // MediaCodecUtil.DecoderQueryException constructor is private, cannot create
            // DefaultDrmSessionManager.MissingSchemeDataException constructor is private, cannot create
            // Crypto Exceptions cannot be instantiated, it throws a RuntimeException("Stub!")
    );
}
 
Example #17
Source File: PlayerService.java    From AndroidAudioExample with MIT License 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        @SuppressLint("WrongConstant") 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(this, 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)));
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
 
Example #18
Source File: ExoMediaSourceHelper.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
public void setCache(Cache cache) {
    this.mCache = cache;
}
 
Example #19
Source File: ExoMediaSourceHelper.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
private Cache newCache() {
    return new SimpleCache(
            new File(mAppContext.getExternalCacheDir(), "exo-video-cache"),//缓存目录
            new LeastRecentlyUsedCacheEvictor(512 * 1024 * 1024),//缓存大小,默认512M,使用LRU算法实现
            new ExoDatabaseProvider(mAppContext));
}
 
Example #20
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the {@link Cache} instance. */
public Cache getCache() {
  return cache;
}
 
Example #21
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the {@link Cache} instance. */
public Cache getCache() {
  return cache;
}
 
Example #22
Source File: DownloaderConstructorHelper.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/** Returns the {@link Cache} instance. */
public Cache getCache() {
  return cache;
}
 
Example #23
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a {@link DownloadManager}.
 *
 * @param context Any context.
 * @param databaseProvider Provides the SQLite database in which downloads are persisted.
 * @param cache A cache to be used to store downloaded data. The cache should be configured with
 *     an {@link CacheEvictor} that will not evict downloaded content, for example {@link
 *     NoOpCacheEvictor}.
 * @param upstreamFactory A {@link Factory} for creating {@link DataSource}s for downloading data.
 */
public DownloadManager(
    Context context, DatabaseProvider databaseProvider, Cache cache, Factory upstreamFactory) {
  this(
      context,
      new DefaultDownloadIndex(databaseProvider),
      new DefaultDownloaderFactory(new DownloaderConstructorHelper(cache, upstreamFactory)));
}
 
Example #24
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a {@link DownloadManager}.
 *
 * @param context Any context.
 * @param databaseProvider Provides the SQLite database in which downloads are persisted.
 * @param cache A cache to be used to store downloaded data. The cache should be configured with
 *     an {@link CacheEvictor} that will not evict downloaded content, for example {@link
 *     NoOpCacheEvictor}.
 * @param upstreamFactory A {@link Factory} for creating {@link DataSource}s for downloading data.
 */
public DownloadManager(
    Context context, DatabaseProvider databaseProvider, Cache cache, Factory upstreamFactory) {
  this(
      context,
      new DefaultDownloadIndex(databaseProvider),
      new DefaultDownloaderFactory(new DownloaderConstructorHelper(cache, upstreamFactory)));
}
 
Example #25
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a {@link DownloadManager}.
 *
 * @param context Any context.
 * @param databaseProvider Provides the SQLite database in which downloads are persisted.
 * @param cache A cache to be used to store downloaded data. The cache should be configured with
 *     an {@link CacheEvictor} that will not evict downloaded content, for example {@link
 *     NoOpCacheEvictor}.
 * @param upstreamFactory A {@link Factory} for creating {@link DataSource}s for downloading data.
 */
public DownloadManager(
    Context context, DatabaseProvider databaseProvider, Cache cache, Factory upstreamFactory) {
  this(
      context,
      new DefaultDownloadIndex(databaseProvider),
      new DefaultDownloaderFactory(new DownloaderConstructorHelper(cache, upstreamFactory)));
}
 
Example #26
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link Factory} for downloading data.
 */
public DownloaderConstructorHelper(Cache cache, Factory upstreamDataSourceFactory) {
  this(cache, upstreamDataSourceFactory, null, null, null);
}
 
Example #27
Source File: ExoPlayerUtils.java    From ARVI with Apache License 2.0 2 votes vote down vote up
/**
 * Creates/retrieves the {@link com.google.android.exoplayer2.ExoPlayer} {@link Cache} of the default
 * size {@link #DEFAULT_CACHE_SIZE}.
 *
 * @param context the context
 * @return the {@link com.google.android.exoplayer2.ExoPlayer} {@link Cache}
 */
public static synchronized Cache getCache(@NonNull Context context) {
    return getCache(context, DEFAULT_CACHE_SIZE);
}
 
Example #28
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link Factory} for downloading data.
 */
public DownloaderConstructorHelper(Cache cache, Factory upstreamDataSourceFactory) {
  this(cache, upstreamDataSourceFactory, null, null, null);
}