Try Following:
First import the AVFoundation/AVFoundation.h framework.
#import <AVFoundation/AVFoundation.h>
-(void)pickAudioFiles
{
MPMediaPickerController *soundPicker=[[MPMediaPickerController alloc]
initWithMediaTypes:MPMediaTypeAnyAudio];
soundPicker.delegate=self;
soundPicker.allowsPickingMultipleItems=NO; // You can set it to yes for multiple selection
[self presentViewController:soundPicker animated:YES completion:nil];
}
-(void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:
(MPMediaItemCollection *)mediaItemCollection
{
MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0]; // For multiple you can iterate iTems array
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
[mediaPicker dismissViewControllerAnimated:YES completion:nil];
AVPlayerItem *playerItem=[AVPlayerItem playerItemWithURL:url];
AVPlayer *player=[[AVPlayer alloc] initWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer=[AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame=CGRectMake(0, 0, 10, 10);
[self.view.layer addSublayer:playerLayer];
}
You can play with
[player play]
Note : If you want to load all data at once please look at following link. This might help you in all at once case.
Fetch All Audio & Video files in ios