Skip to content

Instantly share code, notes, and snippets.

@dhilipsiva
Created August 9, 2012 15:07
Show Gist options
  • Save dhilipsiva/3304992 to your computer and use it in GitHub Desktop.
Save dhilipsiva/3304992 to your computer and use it in GitHub Desktop.
Code to Copy from iPod Library to App's Directory
//Implement this in the MPMediaPickerControllerDelegate
-(void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection{
NSString *tempPath = NSTemporaryDirectory();
int i=1;
for (MPMediaItem *theItem in mediaItemCollection.items) {
NSURL *url = [theItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset presetName: AVAssetExportPresetPassthrough];
exporter.outputFileType = @"com.apple.coreaudio-format";
NSString *fname = [[NSString stringWithFormat:@"%d",i] stringByAppendingString:@".caf"];
++i;
NSString *exportFile = [tempPath stringByAppendingPathComponent: fname];
exporter.outputURL = [NSURL fileURLWithPath:exportFile];
[exporter exportAsynchronouslyWithCompletionHandler:^{
//Code for completion Handler
}];
}
[picker dismissViewControllerAnimated:YES completion:Nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment