zoukankan      html  css  js  c++  java
  • Android视频/音频缓存框架AndroidVideoCache

    AndroidVideoCache是一个视频/音频缓存库,利用本地代理实现了边下边播,使用起来非常简单。

    HttpProxyCacheServer是主要类,是一个代理服务器,可以配置缓存文件的数量、缓存文件的大小、缓存文件的目录和缓存文件命名算法,文件缓存均基于LRU算法,利用Builder来配置:

    //配置缓存目录
    public Builder cacheDirectory(File file);
    
    //配置缓存文件命名规则
    public Builder fileNameGenerator(FileNameGenerator fileNameGenerator) ;
    
    //配置缓存文件大小
    public Builder maxCacheSize(long maxSize) ;
    
    //配置缓存文件数量
    public Builder maxCacheFilesCount(int count) ;

    建议以单列模式将HttpProxyCacheServer存放于Application中:

    public class App extends Application {
    
        private HttpProxyCacheServer proxy;
    
        public static HttpProxyCacheServer getProxy(Context context) {
            App app = (App) context.getApplicationContext();
            return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
        }
    
        private HttpProxyCacheServer newProxy() {
            return new HttpProxyCacheServer(this);
        }
    }

    调用十分方便,只需要增加一行代码:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
        HttpProxyCacheServer proxy = getProxy();
        String proxyUrl = proxy.getProxyUrl(VIDEO_URL);
        videoView.setVideoPath(proxyUrl);
    }
    
    private HttpProxyCacheServer getProxy() {
        return App.getProxy(getApplicationContext());
    }
  • 相关阅读:
    solr初步了解
    jieba初步了解
    情感计算emokit
    常用命令
    java跨域访问问题记录
    mysql 免安装版配置
    Android 图片缩放方法
    spring android http
    sql join 与where的区别
    android activitygroup 使用
  • 原文地址:https://www.cnblogs.com/alexthecoder/p/5082470.html
Copyright © 2011-2022 走看看