MPPlayerDemo icon indicating copy to clipboard operation
MPPlayerDemo copied to clipboard

proxyUrl用错了

Open yxh265 opened this issue 3 years ago • 2 comments

测试发现缓存的10%完全没有用,会被放到一个另外名字的文件夹和直接播放的文件不一样。其实就代码写错了一个地方

原来的代码
NSURL *proxyUrl = [KTVHTTPCache proxyURLWithOriginalURL: [NSURL URLWithString:urlStr]];
    KTVHCDataCacheItem *item = [KTVHTTPCache cacheCacheItemWithURL:proxyUrl];
    double cachePrecent = 1.0 * item.cacheLength / item.totalLength;
    // 判断缓存已经超过10%了
    if (cachePrecent >= self.preloadPrecent)
        return nil;
    KTVHCDataRequest *req = [[KTVHCDataRequest alloc] initWithURL:proxyUrl headers:[NSDictionary dictionary]];
    KTVHCDataLoader *loader = [KTVHTTPCache cacheLoaderWithRequest:req];
    XSTPreLoaderModel *preModel = [[XSTPreLoaderModel alloc] initWithURL:urlStr loader:loader];
    return preModel;
里面的这一行代码:
KTVHCDataCacheItem *item = [KTVHTTPCache cacheCacheItemWithURL:proxyUrl];
和
KTVHCDataRequest *req = [[KTVHCDataRequest alloc] initWithURL:proxyUrl headers:[NSDictionary dictionary]];
应该是:
KTVHCDataCacheItem *item = [KTVHTTPCache cacheCacheItemWithURL:[NSURL URLWithString:urlStr]];
和
KTVHCDataRequest *req = [[KTVHCDataRequest alloc] initWithURL:[NSURL URLWithString:urlStr] headers:[NSDictionary dictionary]];

yxh265 avatar Dec 21 '21 05:12 yxh265

确实直接使用URL比较好,但是现在缓存也可以生效。 proxyURL会请求localServer,localServer会解析originURL再去请求,请求回来先存储originURL的CacheData,返回之后又存储proxyURL的CacheData,本地就有两份缓存。

ChiHoc avatar Feb 15 '22 07:02 ChiHoc

修改后能获取准确的缓存进度,减少缓存占用。

ChiHoc avatar Feb 15 '22 07:02 ChiHoc