【发布时间】:2011-02-24 08:42:10
【问题描述】:
在我的项目中,我正在连接一个 url,并且正在使用 MPMoviePlayerViewController 观看视频。但这对我来说还不够。我还想将文件保存到我的 Iphone。我必须按纽。一是观看视频,二是保存视频。当我按下按钮手表时,我正在观看它。但无法保存。通过这个,我希望以后能够观看视频。所以在另一个视图中,我想查看保存的视频等。有没有人可以帮助我或者可以指导一下?我尝试了以下代码短语,但是当代码启动时,它可以工作一段时间(可能是下载时间),但是当需要保存时,我收到 Bad EXC_BAD_ACCESS 错误。谢谢大家。
这是我的代码。
CFStringRef *docsDirectory = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.mp4"];
NSString *temPath=NSTemporaryDirectory();
NSString *tempfile=[temPath stringByAppendingPathComponent:@"recode.mp4"];
NSLog(@" DOSYA ADI MADI %@",docsDirectory);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = [[NSError alloc] init];
[fileManager removeItemAtPath:docsDirectory error:&error];
NSURL *url = [NSURL URLWithString:@"http://video.teknomart.com.tr/3-13-2.mp4"];
NSMutableURLRequest *liveRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[liveRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[liveRequest setValue:@"headervalue" forHTTPHeaderField:@"headerfield"];
NSURLResponse *response;
NSData *myData = [NSURLConnection sendSynchronousRequest:liveRequest returningResponse:&response error:&error];
NSData *myData2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://video.teknomart.com.tr/3-13-2.mp4"]];
NSString *myString=[[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
NSLog(@"gelen sey %@",myString);
[myString writeToFile:tempfile writeToFile:tempfile automatically:YES encoding:NSASCIIStringEncoding error:nil];
[myString release];
return true;
【问题讨论】:
标签: iphone xcode filesystems stream save