本文整理汇总了Java中com.danikula.videocache.HttpProxyCacheServer类的典型用法代码示例。如果您正苦于以下问题:Java HttpProxyCacheServer类的具体用法?Java HttpProxyCacheServer怎么用?Java HttpProxyCacheServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpProxyCacheServer类属于com.danikula.videocache包,在下文中一共展示了HttpProxyCacheServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readProxyResponse
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
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();
}
}
示例2: startPrepare
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
/**
* 开始准备播放(直接播放)
*/
protected void startPrepare() {
if (mCurrentUrl == null || mCurrentUrl.trim().equals("")) return;
try {
if (isCache) {
HttpProxyCacheServer cacheServer = getCacheServer();
String proxyPath = cacheServer.getProxyUrl(mCurrentUrl);
cacheServer.registerCacheListener(cacheListener, mCurrentUrl);
if (cacheServer.isCached(mCurrentUrl)) {
bufferPercentage = 100;
}
mMediaPlayer.setDataSource(proxyPath);
} else {
mMediaPlayer.setDataSource(mCurrentUrl);
}
mMediaPlayer.prepareAsync();
mCurrentState = STATE_PREPARING;
setPlayState(mCurrentState);
setPlayerState(isFullScreen() ? PLAYER_FULL_SCREEN : PLAYER_NORMAL);
} catch (Exception e) {
mCurrentState = STATE_ERROR;
setPlayState(mCurrentState);
e.printStackTrace();
}
}
示例3: resolveChangeUrl
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
private void resolveChangeUrl(boolean cacheWithPlay, File cachePath, String url) {
if (mTmpManager != null) {
mCache = cacheWithPlay;
mCachePath = cachePath;
mOriginUrl = url;
if (cacheWithPlay && url.startsWith("http") && !url.contains("127.0.0.1") && !url.contains(".m3u8")) {
HttpProxyCacheServer proxy = (cachePath != null) ?
mTmpManager.newProxy(getActivityContext().getApplicationContext(), cachePath) : mTmpManager.newProxy(getActivityContext().getApplicationContext());
//此处转换了url,然后再赋值给mUrl。
url = proxy.getProxyUrl(url);
mCacheFile = (!url.startsWith("http"));
mTmpManager.setProxy(proxy);
//注册上缓冲监听
if (!mCacheFile && GSYVideoManager.instance() != null) {
proxy.registerCacheListener(GSYVideoManager.instance(), mOriginUrl);
}
} else if (!cacheWithPlay && (!url.startsWith("http") && !url.startsWith("rtmp")
&& !url.startsWith("rtsp") && !url.contains(".m3u8"))) {
mCacheFile = true;
}
this.mUrl = url;
}
}
示例4: readProxyResponse
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
public static Response readProxyResponse(HttpProxyCacheServer proxy, String url, int offset) throws IOException {
String proxyUrl = proxy.getProxyUrl(url);
if (!proxyUrl.startsWith("http://127.0.0.1")) {
throw new IllegalStateException("Url " + url + " is not proxied!");
}
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();
}
}
示例5: checkCachedState
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
private void checkCachedState() {
HttpProxyCacheServer proxy = App.getProxy(getActivity());
boolean fullyCached = proxy.isCached(url);
setCachedState(fullyCached);
if (fullyCached) {
progressBar.setSecondaryProgress(100);
}
}
示例6: startVideo
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
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();
}
示例7: getPort
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
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);
}
示例8: display
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
@Override
public void display(Context context, ViewGroup layout) {
/* Proxy Url for caching */
HttpProxyCacheServer proxy = VideoCacheProxyManager.getProxy(context);
String proxyUrl = proxy.getProxyUrl(mUrl);
mVideoView = addOrReplaceViewByType(layout, context, VideoView.class);
//Use a media controller so that you can scroll the video contents
//and also to pause, start the video.
MediaController mediaController = new MediaController(context);
mediaController.setAnchorView(mVideoView);
mVideoView.setMediaController(mediaController);
mVideoView.setVideoPath(proxyUrl);
mVideoView.setOnCompletionListener(onMediaCompletionListener);
}
示例9: newProxy
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
/**
* 创建缓存代理服务,带文件目录的.
*/
public HttpProxyCacheServer newProxy(Context context, File file) {
if (!file.exists()) {
file.mkdirs();
}
HttpProxyCacheServer.Builder builder = new HttpProxyCacheServer.Builder(context);
builder.cacheDirectory(file);
builder.headerInjector(new UserAgentHeadersInjector());
cacheFile = file;
return builder.build();
}
示例10: setUp
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
/**
* 设置播放URL
*
* @param url 播放url
* @param cacheWithPlay 是否边播边缓存
* @param cachePath 缓存路径,如果是M3U8或者HLS,请设置为false
* @param title title
* @return
*/
public boolean setUp(String url, boolean cacheWithPlay, File cachePath, String title) {
mCache = cacheWithPlay;
mCachePath = cachePath;
mOriginUrl = url;
if (isCurrentMediaListener() &&
(System.currentTimeMillis() - mSaveChangeViewTIme) < CHANGE_DELAY_TIME)
return false;
mCurrentState = CURRENT_STATE_NORMAL;
if (cacheWithPlay && url.startsWith("http") && !url.contains("127.0.0.1") && !url.contains(".m3u8")) {
HttpProxyCacheServer proxy = GSYVideoManager.getProxy(getActivityContext().getApplicationContext(), cachePath);
//此处转换了url,然后再赋值给mUrl。
url = proxy.getProxyUrl(url);
mCacheFile = (!url.startsWith("http"));
//注册上缓冲监听
if (!mCacheFile && GSYVideoManager.instance() != null) {
proxy.registerCacheListener(GSYVideoManager.instance(), mOriginUrl);
}
} else if (!cacheWithPlay && (!url.startsWith("http") && !url.startsWith("rtmp")
&& !url.startsWith("rtsp") && !url.contains(".m3u8"))) {
mCacheFile = true;
}
this.mUrl = url;
this.mTitle = title;
setStateAndUi(CURRENT_STATE_NORMAL);
return true;
}
示例11: buildCacheProxy
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
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();
}
示例12: onCreate
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_view);
Intent intent=getIntent();
String videourl= intent.getStringExtra("video");
/*
Uri uri = Uri.parse(videourl);
//调用系统自带的播放器
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
finish();*/
//Uri uri = Uri.parse(videourl);
UniversalVideoView videoView=(UniversalVideoView) findViewById(R.id.video_v);
HttpProxyCacheServer proxy = getProxy();
String proxyUrl = proxy.getProxyUrl(videourl);
videoView.setVideoPath(proxyUrl);
//videoView.setMediaController(new MediaController(this));
videoView.setMediaController(new UniversalMediaController(this));
videoView.setFullscreen(true);
videoView.setFitXY(true);
videoView.start();
videoView.requestFocus();
}
示例13: getProxy
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
public static HttpProxyCacheServer getProxy(Context context, long size) {
if(proxyCacheServer == null
|| previousProxyCacheSize == -1
|| size != previousProxyCacheSize) {
if(proxyCacheServer != null) {
proxyCacheServer.shutdown();
}
proxyCacheServer = new HttpProxyCacheServer.Builder(context)
.maxCacheSize(size)
.build();
previousProxyCacheSize = size;
}
return proxyCacheServer;
}
示例14: proxyURL
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
public static String proxyURL(Context context, SharedPreferences preferences, String url) {
if(preferences.getBoolean("prefCacheVideos", false)) {
long cacheLimit = Integer.parseInt(preferences.getString("prefCacheLimit", "512"));
HttpProxyCacheServer proxy = getProxy(context,
cacheLimit * 1024 * 1024);
return proxy.getProxyUrl(url);
} else {
return url;
}
}
示例15: onCreate
import com.danikula.videocache.HttpProxyCacheServer; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// LeakCanary.install(this);
if (ProcessPhoenix.isPhoenixProcess(this)) {
return;
}
proxy = new HttpProxyCacheServer.Builder(this).maxCacheSize(5*1024).maxCacheFilesCount(20).build();
UpgradeUtil.upgrade(getApplicationContext());
doMainStuff();
}