有没有办法将视频保存在缓存中,然后在需要时进行修改?将视频保存在缓存中
NSCache *memoryCache; //assume there is a memoryCache for images or videos
NSString *urlString = @"http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg";
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"A"] ofType:@"mov"];
NSURL *url = [NSURL fileURLWithPath:path];
NSData *downloadedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^
{
if (downloadedData)
{
// STORE IN FILESYSTEM
NSString* path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *file = [path stringByAppendingPathComponent:@"B.mov"];
[downloadedData writeToFile:file options:NSDataWritingAtomic error:nil];
NSLog(@"Cache File : %@", file);
// STORE IN MEMORY
[memoryCache setObject:downloadedData forKey:@"B.mov"];
}
// NOW YOU CAN CREATE AN AVASSET OR UIIMAGE FROM THE FILE OR DATA
});
我发现这个代码堆栈溢出,但它似乎并没有工作。
欧普,你有你的答案吗? – Pawan 2015-04-06 09:07:31
仍然混淆了缓存目录的行为 – 2015-04-06 09:10:50
缓存目录的内容是否会在应用终止时被删除? – 2015-04-06 09:12:41