android视频播放边播边缓存

导入第三方库:

implementation 'com.danikula:videocache:2.7.0'

在项目Application类中加入以下代码:

private HttpProxyCacheServer proxy;

public static HttpProxyCacheServer getVideoCacheProxy(Context context) {
        App app = (App) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer(this);
    }

播放时使用:

jzVideoPlayerStandard.setUp(App.getVideoCacheProxy(mContext).getProxyUrl(topicBean.getAd()), JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL, "");

博主这里使用的是饺子播放器进行播放,原理都一样,使用时将你的原视频url通过App.getVideoCacheProxy(mContext).getProxyUrl(url)处理一下就行。

猜你喜欢

转载自blog.csdn.net/yonghuming_jesse/article/details/107956343