2

I had imported an .mp3 file form MPMediaPickerController by below code:-

MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];

    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = YES;
    mediaPicker.prompt = @"Select songs to play";

    [self presentModalViewController:mediaPicker animated:YES];
    [mediaPicker release];

Now i want to Convert the selected .mp3 file into NSDATA so that i can upload that nsdata into the server :-

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{

    MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
    [musicPlayer setQueueWithItemCollection: mediaItemCollection];

    NSLog(@"==>%@",musicPlayer);
    [musicPlayer play];
    [self dismissModalViewControllerAnimated: YES];
}

The main problem in how do i convert musicfile into the NSDATA or into anyother format through which i can upload it into the server.Can then can easily use that after downloading the same file as audio file

ios developer
  • 3,363
  • 3
  • 51
  • 111

1 Answers1

0

you can use this to convert .mp3 or any media file to convert into nsdata :-

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSURL *soundFileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/memo.m4a", documentsDirectory]];;
NSData *myData = [NSData dataWithContentsOfURL:soundFileURL];

return myData;
Rock
  • 1,408
  • 1
  • 12
  • 27