Java Code Examples for com.danikula.videocache.HttpProxyCacheServer#getProxyUrl()

The following examples show how to use com.danikula.videocache.HttpProxyCacheServer#getProxyUrl() . These examples are extracted from open source projects. 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
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 2
Source Project: DKVideoPlayer   File: CacheActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
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 4
Source Project: AndriodVideoCache   File: VideoFragment.java    License: Apache License 2.0 5 votes vote down vote up
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 5
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 6
Source Project: DKVideoPlayer   File: ADActivity.java    License: Apache License 2.0 5 votes vote down vote up
@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 7
@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
@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 9
Source Project: AndroidVideoCache   File: VideoFragment.java    License: Apache License 2.0 5 votes vote down vote up
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 10
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 11
Source Project: QSVideoPlayer   File: CacheManager.java    License: Apache License 2.0 4 votes vote down vote up
public static String buildCahchUrl(Context context, String rawUrl, Map<String, String> headers) {
    HttpProxyCacheServer proxy = Proxy.getProxy(context, headers);
    return proxy.getProxyUrl(rawUrl);
}