From a2e6fcbb0780835bc45d1a01d5c31d9a4e073792 Mon Sep 17 00:00:00 2001 From: Lucky Pal Date: Wed, 22 Jun 2022 20:58:57 -0400 Subject: [PATCH] Use absolute file URL for cached video (#26) --- ios/VideoCache.m | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ios/VideoCache.m b/ios/VideoCache.m index ffc7548..250ba67 100644 --- a/ios/VideoCache.m +++ b/ios/VideoCache.m @@ -14,7 +14,17 @@ @implementation VideoCache return url; } } - return [KTVHTTPCache proxyURLWithOriginalURL:[NSURL URLWithString:url]].absoluteString; + NSURL* videoUrl = [NSURL URLWithString:url]; + @try { + NSURL *completedCacheFileURL = [KTVHTTPCache cacheCompleteFileURLWithURL:videoUrl]; + if (completedCacheFileURL != nil) { + return completedCacheFileURL.absoluteString; + } + } + @catch (NSException *exception) { + } + + return [KTVHTTPCache proxyURLWithOriginalURL:videoUrl].absoluteString; } RCT_EXPORT_METHOD(convertAsync:(NSString *)url @@ -29,7 +39,17 @@ @implementation VideoCache return; } } - resolve([KTVHTTPCache proxyURLWithOriginalURL:[NSURL URLWithString:url]].absoluteString); + NSURL* videoUrl = [NSURL URLWithString:url]; + @try { + NSURL *completedCacheFileURL = [KTVHTTPCache cacheCompleteFileURLWithURL:videoUrl]; + if (completedCacheFileURL != nil) { + resolve(completedCacheFileURL.absoluteString); + return; + } + } + @catch (NSException *exception) { + } + resolve([KTVHTTPCache proxyURLWithOriginalURL:videoUrl].absoluteString); } @end