ExoPlayer cache

前端 未结 3 1354
孤独总比滥情好
孤独总比滥情好 2020-12-28 18:22

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

相关标签:
3条回答
  • 2020-12-28 18:46

    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);
    
    0 讨论(0)
  • 2020-12-28 18:52

    I use exoplayer with this library: https://github.com/danikula/AndroidVideoCache It helps you cache the video from a resource (URL, file)...

    This is my sample code:

    String mediaURL = "https://my_cool_vid.com/vi.mp4";
    SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext());
    HttpProxyCacheServer proxyServer = HttpProxyCacheServer.Builder(getContext()).maxCacheSize(1024 * 1024 * 1024).build();
    
    String proxyURL = proxyServer.getProxyUrl(mediaURL);
    
    
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(),
                    Util.getUserAgent(getContext(), getActivity().getApplicationContext().getPackageName()));
    
    
    exoPlayer.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory)
                    .createMediaSource(Uri.parse(proxyURL)););
    
    0 讨论(0)
  • 2020-12-28 19:03

    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.

    0 讨论(0)
提交回复
热议问题