iPhone保存电影剪辑 - 不适用于3GS

时间:2011-07-15 16:45:31

标签: iphone objective-c

以下代码适用于iPad和iPhone / iPod 4,但不适用于3G / 3GS,这意味着影片剪辑无法保存。我们的测试3G / 3GS设备上的操作系统是> 4.0。

-(void)processMovieClipSave:(NSConnection*)connection
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

SystemSoundID snapShot;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"tapsound" ofType:@"wav"]],&snapShot);
AudioServicesPlaySystemSound(snapShot);

NSData* data = [NSData dataWithContentsOfURL:moviePlayerController.contentURL];
NSString* path = nil;
NSString *paths = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
path = [paths stringByAppendingPathComponent:@"/src.mp4"];
[data writeToFile:path atomically:NO];

NSURL *clipURL = [NSURL URLWithString:path];
//NSLog(@"Save Clip URL: %@",[clipURL absoluteString]);

ALAssetsLibrary* library = [[[ALAssetsLibrary alloc]init]autorelease];
[library writeVideoAtPathToSavedPhotosAlbum:clipURL completionBlock:^(NSURL *assetURL, NSError *error) 
 {
     NSMutableDictionary *dict = nil;
     if (error)
     {
         dict = [[NSMutableDictionary alloc]init];
         [dict setObject:error forKey:@"error"];
     }

     [self performSelectorOnMainThread:@selector(onMovieClipSaved:) withObject:dict waitUntilDone:NO];

     if (dict)
         [dict release];
 }];

[pool release];

}

0 个答案:

没有答案