ExoPlayer cache

2019-03-12 17:51发布

I'm traying to use ExoPlayer for playback video over http. And I want to save video after video was loaded and play it from cache. How Do implement cache and playback from cache? Can give me any samples.

2条回答
太酷不给撩
2楼-- · 2019-03-12 18:20

You use cacheDataSource created using cache and dataSource. This cacheDataSource is then used by ExtractorSampleSource.Below is the code for audioRenderer, similarly can be done for videoRender; passing to exoplayerInstance.prepare(renderers).

Cache cache = new SimpleCache(mCtx.getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 10));
DataSource dataSource = new DefaultUriDataSource(mCtx, "My Player");
CacheDataSource cacheDataSource = new CacheDataSource(cache, dataSource, false, false);
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
ExtractorSampleSource extractorSampleSource = new ExtractorSampleSource(trackURI, cacheDataSource, allocator, BUFFER_SEGMENT_COUNT*BUFFER_SEGMENT_SIZE, new Mp3Extractor());
MediaCodecAudioTrackRenderer audioTrackRenderer = new MediaCodecAudioTrackRenderer(extractorSampleSource);
查看更多
贪生不怕死
3楼-- · 2019-03-12 18:30

What protocol are you using mpeg-dash or plain http.

You can override HttpDataSource and write incoming bytes to a file and when playing again check if file exists at the desired location and change the InputStream fed to the player from your file instead of HttpDataSource.

查看更多
登录 后发表回答