Loading ios/RCTVideo.m +2 −2 Changes for ios/RCTVideo.m: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -765,10 +765,10 @@ static NSString *const timedMetadata = @"timedMetadata"; - (void)dvAssetLoaderDelegate:(DVAssetLoaderDelegate *)loaderDelegate didLoadData:(NSData *)data forURL:(NSURL *)url { NSLog(@"File size is : %.2f MB",(float)data.length/1024.0f/1024.0f); [_videoCache storeItem:data forUri:[url absoluteString] withCallback:^(BOOL success) { #ifdef DEBUG NSLog(@"data stored succesfully 🎉"); #endif }]; } Loading ios/RCTVideoCache.m +5 −13 Changes for ios/RCTVideoCache.m: 5 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -47,11 +47,11 @@ withIntermediateDirectories:YES attributes:nil error:&error]; #ifdef DEBUG if (!success || error) { NSLog(@"Error! %@", error); } else { NSLog(@"Success!"); NSLog(@"Error while! %@", error); } #endif } - (void)storeItem:(NSData *)data forUri:(NSString *)uri withCallback:(void(^)(BOOL))handler; Loading @@ -60,9 +60,11 @@ [self saveDataToTemporaryStorage:data key:key]; [self.videoCache storeData:data forKey:key locked:NO withCallback:^(SPTPersistentCacheResponse * _Nonnull response) { if (response.error) { #ifdef DEBUG NSLog(@"An error occured while saving the video into the cache: %@", [response.error localizedDescription]); handler(NO); return; #endif } handler(YES); } onQueue:dispatch_get_main_queue()]; Loading @@ -74,10 +76,8 @@ BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:temporaryFilePath]; if (!fileExists) { NSLog(@"Temporary file does not exist"); return nil; } NSLog(@"Temporary file does exist"); NSURL * assetUrl = [[NSURL alloc] initFileURLWithPath:temporaryFilePath]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:assetUrl options:nil]; return asset; Loading @@ -85,7 +85,6 @@ - (BOOL)saveDataToTemporaryStorage:(NSData *)data key:(NSString *)key { NSString * temporaryFilePath = [self.temporaryCachePath stringByAppendingPathComponent:key]; NSLog(@"Temporary path %@", temporaryFilePath); [data writeToFile:temporaryFilePath atomically:YES]; return YES; } Loading @@ -93,23 +92,17 @@ - (void)getItemForUri:(NSString *)uri withCallback:(void(^)(AVAsset * _Nullable)) handler { NSString * key = [[self generateHashForUrl:uri] stringByAppendingPathExtension: [uri pathExtension]]; NSLog(@"LOADING FROM TEMPORARY STORAGE %@", key); AVURLAsset * temporaryAsset = [self getItemFromTemporaryStorage:key]; if (temporaryAsset != nil) { NSLog(@"FOUND IN TEMPORARY STORAGE"); handler(temporaryAsset); return; } NSLog(@"NOT FOUND IN TEMPORARY STORAGE"); NSLog(@"LOAD FROM PERSISTENT STORAGE"); [self.videoCache loadDataForKey:key withCallback:^(SPTPersistentCacheResponse * _Nonnull response) { if (response.record == nil || response.record.data == nil) { NSLog(@"NOT FOUND IN PERSISTENT STORAGE"); handler(nil); return; } NSLog(@"FOUND IN PERSISTENT -> SAVE TO TEMPORARY"); [self saveDataToTemporaryStorage:response.record.data key:key]; handler([self getItemFromTemporaryStorage:key]); } onQueue:dispatch_get_main_queue()]; Loading @@ -130,4 +123,3 @@ } @end Loading
ios/RCTVideo.m +2 −2 Changes for ios/RCTVideo.m: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -765,10 +765,10 @@ static NSString *const timedMetadata = @"timedMetadata"; - (void)dvAssetLoaderDelegate:(DVAssetLoaderDelegate *)loaderDelegate didLoadData:(NSData *)data forURL:(NSURL *)url { NSLog(@"File size is : %.2f MB",(float)data.length/1024.0f/1024.0f); [_videoCache storeItem:data forUri:[url absoluteString] withCallback:^(BOOL success) { #ifdef DEBUG NSLog(@"data stored succesfully 🎉"); #endif }]; } Loading
ios/RCTVideoCache.m +5 −13 Changes for ios/RCTVideoCache.m: 5 added lines, 13 removed lines. Original line number Diff line number Diff line Loading @@ -47,11 +47,11 @@ withIntermediateDirectories:YES attributes:nil error:&error]; #ifdef DEBUG if (!success || error) { NSLog(@"Error! %@", error); } else { NSLog(@"Success!"); NSLog(@"Error while! %@", error); } #endif } - (void)storeItem:(NSData *)data forUri:(NSString *)uri withCallback:(void(^)(BOOL))handler; Loading @@ -60,9 +60,11 @@ [self saveDataToTemporaryStorage:data key:key]; [self.videoCache storeData:data forKey:key locked:NO withCallback:^(SPTPersistentCacheResponse * _Nonnull response) { if (response.error) { #ifdef DEBUG NSLog(@"An error occured while saving the video into the cache: %@", [response.error localizedDescription]); handler(NO); return; #endif } handler(YES); } onQueue:dispatch_get_main_queue()]; Loading @@ -74,10 +76,8 @@ BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:temporaryFilePath]; if (!fileExists) { NSLog(@"Temporary file does not exist"); return nil; } NSLog(@"Temporary file does exist"); NSURL * assetUrl = [[NSURL alloc] initFileURLWithPath:temporaryFilePath]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:assetUrl options:nil]; return asset; Loading @@ -85,7 +85,6 @@ - (BOOL)saveDataToTemporaryStorage:(NSData *)data key:(NSString *)key { NSString * temporaryFilePath = [self.temporaryCachePath stringByAppendingPathComponent:key]; NSLog(@"Temporary path %@", temporaryFilePath); [data writeToFile:temporaryFilePath atomically:YES]; return YES; } Loading @@ -93,23 +92,17 @@ - (void)getItemForUri:(NSString *)uri withCallback:(void(^)(AVAsset * _Nullable)) handler { NSString * key = [[self generateHashForUrl:uri] stringByAppendingPathExtension: [uri pathExtension]]; NSLog(@"LOADING FROM TEMPORARY STORAGE %@", key); AVURLAsset * temporaryAsset = [self getItemFromTemporaryStorage:key]; if (temporaryAsset != nil) { NSLog(@"FOUND IN TEMPORARY STORAGE"); handler(temporaryAsset); return; } NSLog(@"NOT FOUND IN TEMPORARY STORAGE"); NSLog(@"LOAD FROM PERSISTENT STORAGE"); [self.videoCache loadDataForKey:key withCallback:^(SPTPersistentCacheResponse * _Nonnull response) { if (response.record == nil || response.record.data == nil) { NSLog(@"NOT FOUND IN PERSISTENT STORAGE"); handler(nil); return; } NSLog(@"FOUND IN PERSISTENT -> SAVE TO TEMPORARY"); [self saveDataToTemporaryStorage:response.record.data key:key]; handler([self getItemFromTemporaryStorage:key]); } onQueue:dispatch_get_main_queue()]; Loading @@ -130,4 +123,3 @@ } @end