Uso del caché en ExoPlayer

Estoy buscando cualquier ejemplo de implementación de caché en ExoPlayer.

ExoPlayer tiene en su biblioteca diferentes clases sobre caché y Google explica en este video que podemos implementarlo con la clase CacheDataSource, pero Google no proporciona ninguna demo en él. Desafortunadamente esto parece bastante complicado de usar, por lo que estoy buscando ejemplos (sin éxito en Google).

¿Cualquier persona tiene éxito o tiene cualquier Info que ayudaría? Gracias.

Aquí hay un ejemplo que reemplaza la fuente de datos de demostración con OkHttp, por defecto no hay caché https://github.com/b95505017/ExoPlayer/commit/ebfdda8e7848a2e2e275f5c0525f614b56ef43a6 https://github.com/b95505017/ExoPlayer/tree/okhttp_http_data_source Necesidad de configurar caché de OkHttp correctamente y las peticiones se deben almacenar en caché.

Lo he implementado de esta manera en el generador de renderizado

private static final int BUFFER_SEGMENT_SIZE = 64 * 1024; private static final int BUFFER_SEGMENT_COUNT = 160; final String userAgent = Util.getUserAgent(mContext, appName); final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); final Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);* Cache cache = new SimpleCache(context.getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 10)); DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); CacheDataSource cacheDataSource = new CacheDataSource(cache, dataSource, false, false); ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri , cacheDataSource , allocator , BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE , new Mp4Extractor()); 

Aquí está la solución para ExoPlayer 2. +

Cree una fábrica de origen de datos de caché personalizada

 class CacheDataSourceFactory implements DataSource.Factory { private final Context context; private final DefaultDataSourceFactory defaultDatasourceFactory; private final long maxFileSize, maxCacheSize; CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) { super(); this.context = context; this.maxCacheSize = maxCacheSize; this.maxFileSize = maxFileSize; String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name)); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); defaultDatasourceFactory = new DefaultDataSourceFactory(this.context, bandwidthMeter, new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter)); } @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); } } 

Y el jugador

 BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); MediaSource audioSource = new ExtractorMediaSource(Uri.parse(url), new CacheDataSourceFactory(context, 100 * 1024 * 1024, 5 * 1024 * 1024), new DefaultExtractorsFactory(), null, null); exoPlayer.setPlayWhenReady(true); exoPlayer.prepare(audioSource); 

Funciona bastante bien.

  • ¿Hay alguna forma de obtener canciones que cuenten canciones o canciones que se hayan reproducido recientemente en Android?
  • ¿Hay algunos reproductores de medios de código abierto en Android?
  • Android SDK Mediaplayer.create devuelve al azar null
  • Biblioteca de música en android
  • Android MediaPlayer OnPreparedListener
  • ¿Cómo puedo consultar los álbumes con MediaBrowser?
  • Android: El uso de los fallos de MIC (a través de setAudioSource)
  • Extraer mapa de bits del vídeo en android
  • Android, ¿cómo establecer los metadatos en el archivo MP4?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.