com.danikula.videocache.HttpProxyCacheServer Java Examples
The following examples show how to use
com.danikula.videocache.HttpProxyCacheServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Reddit.java From Slide with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); mApplication = this; // LeakCanary.install(this); if (ProcessPhoenix.isPhoenixProcess(this)) { return; } proxy = new HttpProxyCacheServer.Builder(this).maxCacheSize(5 * 1024) .maxCacheFilesCount(20) .build(); UpgradeUtil.upgrade(getApplicationContext()); doMainStuff(); }
Example #2
Source File: ProxyCacheTestUtils.java From AndroidVideoCache with Apache License 2.0 | 6 votes |
public static Response readProxyResponse(HttpProxyCacheServer proxy, String url, int offset) throws IOException { String proxyUrl = proxy.getProxyUrl(url, false); if (!proxyUrl.startsWith("http://127.0.0.1")) { throw new IllegalStateException("Proxy url " + proxyUrl + " is not proxied! Original url is " + url); } URL proxiedUrl = new URL(proxyUrl); HttpURLConnection connection = (HttpURLConnection) proxiedUrl.openConnection(); try { if (offset >= 0) { connection.setRequestProperty("Range", "bytes=" + offset + "-"); } return new Response(connection); } finally { connection.disconnect(); } }
Example #3
Source File: CacheActivity.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
@Override protected void initView() { super.initView(); mVideoView = findViewById(R.id.video_view); HttpProxyCacheServer cacheServer = ProxyVideoCacheManager.getProxy(this); String proxyUrl = cacheServer.getProxyUrl(DataUtil.SAMPLE_URL); mVideoView.setUrl(proxyUrl); StandardVideoController controller = new StandardVideoController(this); controller.addDefaultControlComponent(getString(R.string.str_cache), false); mVideoView.setVideoController(controller); mVideoView.start(); //删除url对应默认缓存文件 // ProxyVideoCacheManager.clearDefaultCache(this, URL); //清除缓存文件中的所有缓存 // ProxyVideoCacheManager.clearAllCache(this); }
Example #4
Source File: ProxyCacheTestUtils.java From AndriodVideoCache with Apache License 2.0 | 6 votes |
public static Response readProxyResponse(HttpProxyCacheServer proxy, String url, int offset) throws IOException { String proxyUrl = proxy.getProxyUrl(url, false); if (!proxyUrl.startsWith("http://127.0.0.1")) { throw new IllegalStateException("Proxy url " + proxyUrl + " is not proxied! Original url is " + url); } URL proxiedUrl = new URL(proxyUrl); HttpURLConnection connection = (HttpURLConnection) proxiedUrl.openConnection(); try { if (offset >= 0) { connection.setRequestProperty("Range", "bytes=" + offset + "-"); } return new Response(connection); } finally { connection.disconnect(); } }
Example #5
Source File: ProxyCacheManager.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
/** * 创建缓存代理服务,带文件目录的. */ public HttpProxyCacheServer newProxy(Context context, File file) { if (!file.exists()) { file.mkdirs(); } HttpProxyCacheServer.Builder builder = new HttpProxyCacheServer.Builder(context); builder.cacheDirectory(file); builder.maxCacheSize(DEFAULT_MAX_SIZE); builder.headerInjector(userAgentHeadersInjector); if (fileNameGenerator != null) { builder.fileNameGenerator(fileNameGenerator); } mCacheDir = file; return builder.build(); }
Example #6
Source File: ProxyCacheManager.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
@Override public boolean cachePreview(Context context, File cacheDir, String url) { HttpProxyCacheServer proxy = getProxy(context.getApplicationContext(), cacheDir); if (proxy != null) { //此处转换了url,然后再赋值给mUrl。 url = proxy.getProxyUrl(url); } return (!url.startsWith("http")); }
Example #7
Source File: ProxyCacheManager.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
@Override public void doCacheLogic(Context context, IMediaPlayer mediaPlayer, String originUrl, Map<String, String> header, File cachePath) { String url = originUrl; userAgentHeadersInjector.mMapHeadData.clear(); if (header != null) { userAgentHeadersInjector.mMapHeadData.putAll(header); } if (url.startsWith("http") && !url.contains("127.0.0.1") && !url.contains(".m3u8")) { HttpProxyCacheServer proxy = getProxy(context.getApplicationContext(), cachePath); if (proxy != null) { //此处转换了url,然后再赋值给mUrl。 url = proxy.getProxyUrl(url); mCacheFile = (!url.startsWith("http")); //注册上缓冲监听 if (!mCacheFile) { proxy.registerCacheListener(this, originUrl); } } } else if ((!url.startsWith("http") && !url.startsWith("rtmp") && !url.startsWith("rtsp") && !url.contains(".m3u8"))) { mCacheFile = true; } try { mediaPlayer.setDataSource(context, Uri.parse(url), header); } catch (IOException e) { e.printStackTrace(); } }
Example #8
Source File: Config.java From TigerVideo with Apache License 2.0 | 5 votes |
private HttpProxyCacheServer buildCacheProxy() { return new HttpProxyCacheServer .Builder(context.getApplicationContext()) .cacheDirectory(new File(Utils.getCacheDir(context))) .fileNameGenerator(new Md5FileNameGenerator() { @Override public String generate(String url) { return ProxyCacheUtils.computeMD5(url); } }) .maxCacheFilesCount(20) .build(); }
Example #9
Source File: Proxy.java From QSVideoPlayer with Apache License 2.0 | 5 votes |
synchronized static HttpProxyCacheServer getProxy(Context context, final Map<String, String> headers) { if (builder == null) builder = new HttpProxyCacheServer.Builder(context); if (headers != null) builder.headerInjector(new HeaderInjector() { @Override public Map<String, String> addHeaders(String url) { return headers; } }); return builder.build(); }
Example #10
Source File: MainActivity.java From QSVideoPlayer with Apache License 2.0 | 5 votes |
private void cacheConfig() { Proxy.setConfig(new HttpProxyCacheServer .Builder(this) .cacheDirectory(new File("/sdcard/video")) //.fileNameGenerator() 存储文件名规则 .maxCacheSize(512 * 1024 * 1024)//缓存文件大小 //.maxCacheFilesCount(100)//缓存文件数目 二选一 ); }
Example #11
Source File: ProxyVideoCacheManager.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
private static HttpProxyCacheServer newProxy(Context context) { return new HttpProxyCacheServer.Builder(context) .maxCacheSize(512 * 1024 * 1024) // 512MB for cache //缓存路径,不设置默认在sd_card/Android/data/[app_package_name]/cache中 // .cacheDirectory() .build(); }
Example #12
Source File: ADActivity.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
@Override protected void initView() { super.initView(); mVideoView = findViewById(R.id.video_view); mController = new StandardVideoController(this); AdControlView adControlView = new AdControlView(this); adControlView.setListener(new AdControlView.AdControlListener() { @Override public void onAdClick() { Toast.makeText(ADActivity.this, "广告点击跳转", Toast.LENGTH_SHORT).show(); } @Override public void onSkipAd() { playVideo(); } }); mController.addControlComponent(adControlView); HttpProxyCacheServer cacheServer = ProxyVideoCacheManager.getProxy(this); String proxyUrl = cacheServer.getProxyUrl(URL_AD); mVideoView.setUrl(proxyUrl); mVideoView.setVideoController(mController); //监听播放结束 mVideoView.addOnStateChangeListener(new VideoView.SimpleOnStateChangeListener() { @Override public void onPlayStateChanged(int playState) { if (playState == VideoView.STATE_PLAYBACK_COMPLETED) { playVideo(); } } }); mVideoView.start(); }
Example #13
Source File: ProxyCacheTestUtils.java From AndriodVideoCache with Apache License 2.0 | 5 votes |
public static int getPort(HttpProxyCacheServer server) { String proxyUrl = server.getProxyUrl("test"); Pattern pattern = Pattern.compile("http://127.0.0.1:(\\d*)/test"); Matcher matcher = pattern.matcher(proxyUrl); assertThat(matcher.find()).isTrue(); String portAsString = matcher.group(1); return Integer.parseInt(portAsString); }
Example #14
Source File: VideoFragment.java From AndroidVideoCache with Apache License 2.0 | 5 votes |
private void checkCachedState() { HttpProxyCacheServer proxy = App.getProxy(getActivity()); boolean fullyCached = proxy.isCached(url); setCachedState(fullyCached); if (fullyCached) { progressBar.setSecondaryProgress(100); } }
Example #15
Source File: VideoFragment.java From AndroidVideoCache with Apache License 2.0 | 5 votes |
private void startVideo() { HttpProxyCacheServer proxy = App.getProxy(getActivity()); proxy.registerCacheListener(this, url); String proxyUrl = proxy.getProxyUrl(url); Log.d(LOG_TAG, "Use proxy url " + proxyUrl + " instead of original url " + url); videoView.setVideoPath(proxyUrl); videoView.start(); }
Example #16
Source File: VideoFragment.java From AndriodVideoCache with Apache License 2.0 | 5 votes |
private void startVideo() { HttpProxyCacheServer proxy = App.getProxy(getActivity()); proxy.registerCacheListener(this, url); String proxyUrl = proxy.getProxyUrl(url); Log.d(LOG_TAG, "Use proxy url " + proxyUrl + " instead of original url " + url); videoView.setVideoPath(proxyUrl); videoView.start(); }
Example #17
Source File: ApplicationModule.java From v9porn with MIT License | 5 votes |
@Singleton @Provides static HttpProxyCacheServer providesHttpProxyCacheServer(@ApplicationContext Context context,HeaderInjector headerInjector) { return new HttpProxyCacheServer.Builder(context) // 1 Gb for cache .headerInjector(headerInjector) .maxCacheSize(AppCacheUtils.MAX_VIDEO_CACHE_SIZE) .cacheDirectory(AppCacheUtils.getVideoCacheDir(context)) .fileNameGenerator(new VideoCacheFileNameGenerator()) .build(); }
Example #18
Source File: AppDataManager.java From v9porn with MIT License | 5 votes |
@Inject AppDataManager(DbHelper mDbHelper, PreferencesHelper mPreferencesHelper, ApiHelper mApiHelper, HttpProxyCacheServer httpProxyCacheServer, CookieManager cookieManager, User user) { this.mDbHelper = mDbHelper; this.mPreferencesHelper = mPreferencesHelper; this.mApiHelper = mApiHelper; this.httpProxyCacheServer = httpProxyCacheServer; this.cookieManager = cookieManager; this.user = user; }
Example #19
Source File: ProxyCacheTestUtils.java From AndroidVideoCache with Apache License 2.0 | 5 votes |
public static int getPort(HttpProxyCacheServer server) { String proxyUrl = server.getProxyUrl("test"); Pattern pattern = Pattern.compile("http://127.0.0.1:(\\d*)/test"); Matcher matcher = pattern.matcher(proxyUrl); assertThat(matcher.find()).isTrue(); String portAsString = matcher.group(1); return Integer.parseInt(portAsString); }
Example #20
Source File: HttpProxyUtil.java From imsdk-android with MIT License | 5 votes |
private static HttpProxyCacheServer newProxy(Context context) { return new HttpProxyCacheServer.Builder(context) .fileNameGenerator(new FileNameGenerator() { @Override public String generate(String url) { return findRealUrl(url); } }) .build(); }
Example #21
Source File: AppDataManager.java From v9porn with MIT License | 5 votes |
@Inject AppDataManager(DbHelper mDbHelper, PreferencesHelper mPreferencesHelper, ApiHelper mApiHelper, HttpProxyCacheServer httpProxyCacheServer, CookieManager cookieManager, User user) { this.mDbHelper = mDbHelper; this.mPreferencesHelper = mPreferencesHelper; this.mApiHelper = mApiHelper; this.httpProxyCacheServer = httpProxyCacheServer; this.cookieManager = cookieManager; this.user = user; }
Example #22
Source File: ApplicationModule.java From v9porn with MIT License | 5 votes |
@Singleton @Provides static HttpProxyCacheServer providesHttpProxyCacheServer(@ApplicationContext Context context,HeaderInjector headerInjector) { return new HttpProxyCacheServer.Builder(context) // 1 Gb for cache .headerInjector(headerInjector) .maxCacheSize(AppCacheUtils.MAX_VIDEO_CACHE_SIZE) .cacheDirectory(AppCacheUtils.getVideoCacheDir(context)) .fileNameGenerator(new VideoCacheFileNameGenerator()) .build(); }
Example #23
Source File: VideoFragment.java From AndriodVideoCache with Apache License 2.0 | 5 votes |
private void checkCachedState() { HttpProxyCacheServer proxy = App.getProxy(getActivity()); boolean fullyCached = proxy.isCached(url); setCachedState(fullyCached); if (fullyCached) { progressBar.setSecondaryProgress(100); } }
Example #24
Source File: Manager.java From GSYRecordWave with Apache License 2.0 | 4 votes |
/** * 创建缓存代理服务 */ private HttpProxyCacheServer newProxy(Context context) { return new HttpProxyCacheServer(context.getApplicationContext()); }
Example #25
Source File: ProxyCacheTestUtils.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
public static Response readProxyResponse(HttpProxyCacheServer proxy, String url) throws IOException { return readProxyResponse(proxy, url, -1); }
Example #26
Source File: GalleryVideoFragment.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
private void startProxy() { HttpProxyCacheServer proxy = App.getProxy(getActivity()); proxy.registerCacheListener(this, url); videoView.setVideoPath(proxy.getProxyUrl(url)); }
Example #27
Source File: App.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
private HttpProxyCacheServer newProxy() { return new HttpProxyCacheServer.Builder(this) .cacheDirectory(Utils.getVideoCacheDir(this)) .build(); }
Example #28
Source File: Manager.java From GSYRecordWave with Apache License 2.0 | 4 votes |
public HttpProxyCacheServer getProxy(Context context) { if (mProxy == null) { mProxy = newProxy(context); } return mProxy; }
Example #29
Source File: ProxyCacheTestUtils.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
public static int getPortWithoutPing(HttpProxyCacheServer server) { return (Integer) ReflectUtil.getField(server, "port"); }
Example #30
Source File: ProxyCacheManager.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
/** * 获取缓存代理服务 */ protected static HttpProxyCacheServer getProxy(Context context) { HttpProxyCacheServer proxy = ProxyCacheManager.instance().proxy; return proxy == null ? (ProxyCacheManager.instance().proxy = ProxyCacheManager.instance().newProxy(context)) : proxy; }