Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExoPlayer cache

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.

like image 524
vmtrue Avatar asked Sep 29 '14 08:09

vmtrue


People also ask

How do you cache videos on ExoPlayer?

By default ExoPlayer do not cache media (video, audio, etc...). For example if you want to play an online video file, each time ExoPlayer will open a connection, read data then play it. Fortunately, it provides us some interfaces and implementation classes to support caching media in our app.

What is the use of ExoPlayer?

ExoPlayer is an app-level media player built on top of low-level media APIs in Android. It is an open source project used by Google apps, including YouTube and Google TV. ExoPlayer is highly customizable and extensible, making it capable of many advanced use cases.

What is ExoPlayer v2?

ExoPlayer is an application level media player for Android. It provides an alternative to Android's MediaPlayer API for playing audio and video both locally and over the Internet. ExoPlayer supports features not currently supported by Android's MediaPlayer API, including DASH and SmoothStreaming adaptive playbacks.


2 Answers

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);
like image 65
Saksham Avatar answered Oct 19 '22 12:10

Saksham


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.

like image 28
Dheeraj Sachan Avatar answered Oct 19 '22 13:10

Dheeraj Sachan