亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android VideoCache視頻緩存的方法詳解

 更新時間:2017年07月23日 11:45:41   作者:程序小渣渣  
這篇文章主要介紹了Android VideoCache視頻緩存的方法詳解的相關(guān)資料,AndroidVideoCache是一個視頻/音頻緩存庫,利用本地代理實現(xiàn)了邊下邊播,需要的朋友可以參考下

Android VideoCache視頻緩存的方法詳解

項目中遇到視頻播放,需要加載網(wǎng)絡(luò)url,不可能每次都進行網(wǎng)絡(luò)加載,當(dāng)然了,就需要用到我們的緩存機制

AndroidVideoCache

AndroidVideoCache是一個視頻/音頻緩存庫,利用本地代理實現(xiàn)了邊下邊播,使用起來非常簡單。

HttpProxyCacheServer是主要類,是一個代理服務(wù)器,可以配置緩存文件的數(shù)量、緩存文件的大小、緩存文件的目錄和緩存文件命名算法,文件緩存均基于LRU算法,利用Builder來配置:

//配置緩存目錄
public Builder cacheDirectory(File file);

//配置緩存文件命名規(guī)則
public Builder fileNameGenerator(FileNameGenerator fileNameGenerator) ;

//配置緩存文件大小
public Builder maxCacheSize(long maxSize) ;

//配置緩存文件數(shù)量
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);
  }
}

調(diào)用十分方便,只需要增加一行代碼:

@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());
}

最后視頻加載的 時候需要判斷是否緩存,做一些比如緩沖進度條的隱藏等操作

以上就是Android VideoCache的使用方法詳解,本站關(guān)于Android開發(fā)的文章還有很多,希望大家搜索查閱,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論