Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: select audio file from device and upload

Tags:

ios

I am new to iOS. I am creating a dummy app to upload an audio file from iOS device on local server. So I was wondering if there is a way to open the audio gallery and select the required audio file to upload. Similar to an image gallery.

Is it possible to open audio list and select necessary audio file? If not, what is the alternative?

like image 939
z22 Avatar asked Mar 21 '23 17:03

z22


1 Answers

Add the MediaPlayer.framework in your project

#import <MediaPlayer/MediaPlayer.h>

Display like this:

MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];  
 mediaPicker.delegate = self;  
 mediaPicker.allowsPickingMultipleItems = NO;  
 [self presentViewController:mediaPicker animated:YES completion:nil];  

Implement delegate <MPMediaPickerControllerDelegate>

- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
    [self dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"You picked : %@",mediaItemCollection);
}
like image 82
Khawar Avatar answered Mar 23 '23 08:03

Khawar