ExoPlayer cache

前端 未结 3 1377
孤独总比滥情好
孤独总比滥情好 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: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)););
    

提交回复
热议问题