Android 9.0 使用AndroidVideoCache时不能缓存视频

项目中使用AndroidVideoCache作为视频缓存组件,但是在安卓9.0手机上无法正常缓存,并且报错

主要报错文本:

com.danikula.videocache.ProxyCacheException: Error opening connection for http://127.0.0.1:34851/ping with offset 0. Version: 2.7.0

Caused by: java.io.IOException: Cleartext HTTP traffic to 127.0.0.1 not permitted

 

问题原因:从安卓9.0开始,处于安全因素考虑,默认不再支持http网络请求,需要使用https。

但是在AndroidVideoCache中使用了一个缓存代理地址:http://127.0.0.1,所以,就会报错

 

解决方案:

一、①创建res/xml/network_security_config.xml





    

        Your URL(ex: 127.0.0.1)

    

注意:上述代码的意思是解除对指定网址的限制。

在解除上述视频缓存报错信息时,节点的具体取值如下:

 127.0.0.1

如果需要过滤某个地址,则只写域名即可,不需要写http://。

②修改AndroidManifest.xml

配置android:networkSecurityConfig





    

    

    ...

    

 

二、修改AndroidManifest.xml

启用android:usesCleartextTraffic





    

    

    ...

    

 

三、修改AndroidManifest.xml

降低android:targetSandboxVersion的版本





    

    ...

 

 

 

 

你可能感兴趣的:(Android,9.0)