Skip to content

Commit

Permalink
Merge pull request #1045 from sptramer/timob-6667-18X
Browse files Browse the repository at this point in the history
[TIMOB-6667] Support saving raw video data to the camera roll.
  • Loading branch information
WhichKatieDid committed Dec 18, 2011
2 parents 9e7fd6c + 4feb74e commit 22868a1
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions iphone/Classes/MediaModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ -(void)saveCompletedForVideo:(NSString*)path error:(NSError*)error contextInfo:(
NSDictionary* event = [NSDictionary dictionaryWithObject:path forKey:@"path"];
[NSThread detachNewThreadSelector:@selector(dispatchCallback:) toTarget:self withObject:[NSArray arrayWithObjects:@"success",event,successCallback,nil]];
}

// This object was retained for use in this callback; release it.
[saveCallbacks release];
}

#pragma mark Public APIs
Expand Down Expand Up @@ -919,9 +922,40 @@ -(void)saveToPhotoGallery:(id)arg
}
else if ([mime hasPrefix:@"video/"])
{
NSString * tempFilePath = [blob path];
if (tempFilePath == nil) return;
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(saveCompletedForVideo:error:contextInfo:), [saveCallbacks retain]);
NSString* filePath;
switch ([blob type]) {
case TiBlobTypeFile: {
filePath = [blob path];
break;
}
case TiBlobTypeData: {
// In this case, we need to write the blob data to a /tmp file and then load it.
NSArray* typeinfo = [mime componentsSeparatedByString:@"/"];
TiFile* tempFile = [TiUtils createTempFile:[typeinfo objectAtIndex:1]];
filePath = [tempFile path];

NSError* error = nil;
[blob writeTo:filePath error:&error];

if (error != nil) {
NSDictionary* event = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"problem writing to temporary file %@: %@", filePath, [error localizedDescription]]
forKey:@"error"];
[self dispatchCallback:[NSArray arrayWithObjects:@"error",event,[saveCallbacks valueForKey:@"error"],nil]];
return;
}

// Have to keep the temp file from being deleted when we leave scope, so add it to the userinfo so it can be cleaned up there
[saveCallbacks setValue:tempFile forKey:@"tempFile"];
break;
}
default: {
NSDictionary* event = [NSDictionary dictionaryWithObject:@"invalid media format: MIME type was video/, but data is image"
forKey:@"error"];
[self dispatchCallback:[NSArray arrayWithObjects:@"error",event,[saveCallbacks valueForKey:@"error"],nil]];
return;
}
}
UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(saveCompletedForVideo:error:contextInfo:), [saveCallbacks retain]);
}
}
else if ([image isKindOfClass:[TiFile class]])
Expand Down

0 comments on commit 22868a1

Please sign in to comment.