Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何设置视频缓存的大小? #3009

Closed
ollie100 opened this issue Oct 22, 2020 · 11 comments
Closed

请问如何设置视频缓存的大小? #3009

ollie100 opened this issue Oct 22, 2020 · 11 comments

Comments

@ollie100
Copy link

在代码中有默认视频缓存是512M,现在我想设置成4个G,结果没有生效
public static int DEFAULT_MAX_SIZE = 512 * 1024 * 1024;

我是在Apllication 初始化播放器SDK时设置的:
ProxyCacheManager.DEFAULT_MAX_SIZE = 512 * 8 * 1024 * 1024;
//EXOPlayer内核,支持格式更多
// PlayerFactory.setPlayManager(Exo2PlayerManager.class);
//系统内核模式
// PlayerFactory.setPlayManager(SystemPlayerManager.class);
//ijk内核,默认模式
PlayerFactory.setPlayManager(IjkPlayerManager.class);

    //exo缓存模式,支持m3u8,只支持exo

// CacheFactory.setCacheManager(ExoPlayerCacheManager.class);
//代理缓存模式,支持所有模式,不支持m3u8等,默认
CacheFactory.setCacheManager(ProxyCacheManager.class);

@CarGuo
Copy link
Owner

CarGuo commented Oct 22, 2020

有 bug ,需要自己指定一个缓存目录,调用了 newProxy(Context context, File file) 才会生效

@CarGuo CarGuo closed this as completed Oct 22, 2020
CarGuo added a commit that referenced this issue Oct 22, 2020
@ollie100
Copy link
Author

怎么实现,有具体代码示例看一下吗?

@CarGuo
Copy link
Owner

CarGuo commented Oct 22, 2020

@ollie100 setup 的时候增加 file 或者 setCachePath

@ollie100
Copy link
Author

有没有全局可以设置的缓存大小的方法,这个我得每处播放视频都要加setCachePath

@CarGuo
Copy link
Owner

CarGuo commented Oct 22, 2020

#3009 你可以参考 ProxyCacheManger 自定义一个 CacheManger ,这里我修改补充了下

@ollie100
Copy link
Author

Application初始化:
CacheFactory.setCacheManager(DyCacheManager.class);

//自定义CacheManager
public class DyCacheManager implements ICacheManager, CacheListener {

public static int DEFAULT_MAX_SIZE = 8 * 512 * 1024 * 1024;

//视频代理
protected HttpProxyCacheServer proxy;

protected File mCacheDir;

我自定义了一个CacheManger 了,初始化后还是没有生效

@ollie100
Copy link
Author

你这个setCacheManager是不是没有用,每次都是走getCacheManager
/**

  • 缓存到本地服务工厂

  • Created by guoshuyu on 2018/5/21.
    */
    public class CacheFactory {

    private static Class<? extends ICacheManager> sICacheManager;

    public static void setCacheManager(Class<? extends ICacheManager> cacheManager) {
    sICacheManager = cacheManager;
    }

    public static ICacheManager getCacheManager() {
    if (sICacheManager == null) {
    sICacheManager = ProxyCacheManager.class;
    }
    try {
    return sICacheManager.newInstance();
    } catch (InstantiationException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    }
    return null;
    }
    }

@CarGuo
Copy link
Owner

CarGuo commented Oct 23, 2020

你参考 #3009 的提交修改啊····,设置是正常的

@ollie100
Copy link
Author

我就是按照你说的写的,亲测当缓存的文件夹大于1GB的时候会自动删除最旧的视频,就是缓存会一直在1GB内,是不是AndroidVideoCache最大只能设置1GB。如果是用maxCacheFilesCount是可以超过1GB的。这个就很奇怪呢

@ollie100
Copy link
Author

这是Java long类型的问题,.DEFAULT_MAX_SIZE = 512 * 8 * 1024 * 1024;这样写是不会设置成功的,
DEFAULT_MAX_SIZE = 512 * 8 * 1024 * 1024L;这样设置的数值才是long类型的,长度才够。真实细节决定成败,多谢老哥耐心回复指导。

@Fans1994
Copy link

缓存m3u8怎么实现,看的一脸懵逼

CarGuo added a commit that referenced this issue Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants