有沒有辦法將視頻保存在緩存中,然後在需要時進行修改?將視頻保存在緩存中
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