mercredi 31 décembre 2014

Data not being saved properly


Vote count:

0




I'm getting data from a url (.m4a file), then I'm trying to save the file so I can change it's metadata. I have the code below and it seems like it should be working. The file that is copied in the end is empty (88 bytes).



_previewData = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:@"http://ift.tt/1AKYk2g"]];
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory=[paths objectAtIndex:0];
NSString *path = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"file.mp4"]];
NSFileManager *filemanager;
filemanager = [NSFileManager defaultManager];
[_previewData writeToFile:path atomically:YES];
if ([filemanager fileExistsAtPath:path]) {
// Runs
NSLog(@"It worked");
}
NSLog(@"%@",path);

ANMovie* file = [[ANMovie alloc] initWithFile:path]; // or .mp4
NSData* jpegCover = UIImageJPEGRepresentation(artworkImage, 1.0);
_imageView.image = [UIImage imageWithData:jpegCover];
ANMetadata* metadata = [[ANMetadata alloc] init];
metadata.albumCover = [[ANMetadataImage alloc] initWithImageData:jpegCover type:ANMetadataImageTypeJPG];
[file setMovieMetadata:metadata];
[file close];

_previewData = [NSMutableData dataWithContentsOfFile:path];

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSDictionary *imageItem=@{@"public.mpeg-4-audio":self.previewData};
NSDictionary *textItem=@{@"public.plain-text":self.linkData};

pasteboard.items=@[imageItem,textItem];


asked 26 secs ago







Data not being saved properly

Aucun commentaire:

Enregistrer un commentaire