/** * Returns url that wrap original url and should be used for client (MediaPlayer, ExoPlayer, etc). * <p> * If file for this url is fully cached (it means method {@link #isCached(String)} returns {@code true}) * then file:// uri to cached file will be returned. * <p> * Calling this method has same effect as calling {@link #getProxyUrl(String, boolean)} with 2nd parameter set to {@code true}. * * @param url a url to file that should be cached. * @return a wrapped by proxy url if file is not fully cached or url pointed to cache file otherwise. */ public String getProxyUrl(String url) { return getProxyUrl(url, true); }
@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")); }
@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(); } }
LinkedHashMap map = new LinkedHashMap(); String proxyUrl = ApplicationDemo.getProxy(this).getProxyUrl(VideoConstant.videoUrls[0][9]);
@Override public String convertCacheFromUrl(String url) { return server.getProxyUrl(url); } }
public static String buildCahchUrl(Context context, String rawUrl, Map<String, String> headers) { HttpProxyCacheServer proxy = Proxy.getProxy(context, headers); return proxy.getProxyUrl(rawUrl); }
/** * add cache url when play */ public void setUrlString(Context context, boolean cache, String urlString) { String url = urlString; if (context != null && cache && !TextUtils.isEmpty(urlString) && urlString.startsWith("http")) { url = Manager.newInstance().getProxy(context).getProxyUrl(urlString); } this.mUrlString = url; }
@Override public void setUp(String url, int screen, Object... objects) { if (url.startsWith("http")) { HttpProxyCacheServer proxy = MyApp.getProxy(context); String proxyUrl = proxy.getProxyUrl(url); super.setUp(proxyUrl, screen, objects); } else { super.setUp(url, screen, objects); } }
public void start(String url, int observerHash) { bindPlayerView(url, observerHash); onPlayStateChanged(PlayState.STATE_LOADING); Utils.log(String.format("start loading video, hash=%d, url=%s", mObserverHash, mVideoUrl)); String wrapperUrl = url; if(mConfig.isCacheEnable()) { wrapperUrl = mConfig.getCacheProxy().getProxyUrl(url); } mPlayer.start(wrapperUrl); }
/** * 设置播放 Uri * * @param uri 播放源 * @param settings 播放器配置 */ public void setVideoUri(@NonNull Uri uri, Settings settings) { mContext = settings.getAppContext(); mOriginalUri = uri; mCurrentUri = uri; if (isCanCache(uri.toString())) { HttpProxyCacheServer httpProxyCacheServer = getCacheServer(settings.getAppContext()); mCurrentUri = Uri.parse(httpProxyCacheServer.getProxyUrl(uri.toString())); httpProxyCacheServer.unregisterCacheListener(this); httpProxyCacheServer.registerCacheListener(this, mOriginalUri.toString()); debugLog("转换后的 url:" + mCurrentUri.toString()); if (httpProxyCacheServer.isCached(mOriginalUri.toString())){ mIsCache = true; } } mCurrentState = STATE_PREPARING; notifyStateChange(); Message message = mMediaHandler.obtainMessage(HANDLER_PREPARE); message.obj = settings; mMediaHandler.sendMessage(message); if (mNeedTimeOut) { startTimeOutRunnable(); } }
if (isCache) { HttpProxyCacheServer cacheServer = getCacheServer(); String proxyPath = cacheServer.getProxyUrl(mCurrentUrl); cacheServer.registerCacheListener(cacheListener, mCurrentUrl); if (cacheServer.isCached(mCurrentUrl)) {
/** * 开始准备播放(直接播放) */ protected void startPrepare(boolean needReset) { if (TextUtils.isEmpty(mCurrentUrl) && mAssetFileDescriptor == null){ Log.e("wang","没有url"); if(null!=urlEmptyListener){ urlEmptyListener.onUrlEmpty(); } return; } if (needReset) mMediaPlayer.reset(); if (mAssetFileDescriptor != null) { mMediaPlayer.setDataSource(mAssetFileDescriptor); } else if (mPlayerConfig.isCache && !mCurrentUrl.startsWith("file://")) { mCacheServer = getCacheServer(); String proxyPath = mCacheServer.getProxyUrl(mCurrentUrl); mCacheServer.registerCacheListener(cacheListener, mCurrentUrl); if (mCacheServer.isCached(mCurrentUrl)) { bufferPercentage = 100; } mMediaPlayer.setDataSource(proxyPath, mHeaders); } else { mMediaPlayer.setDataSource(mCurrentUrl, mHeaders); } mMediaPlayer.prepareAsync(); setPlayState(STATE_PREPARING); setPlayerState(isFullScreen() ? PLAYER_FULL_SCREEN : PLAYER_NORMAL); }