iOS: select audio file from device and upload - 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?

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);
}

You should use MPMediaPickerController class for accessing audio files. Refer this for same.

Related

How to Pick/browse audio files from device library like photo library?

I am building an app in which user can pick(from library) or capture(record) image/video/audio.
I have already implemented for video and image media and recoding audio file but while accessing audio from library its crashing on below line. Its working fine when I try to acsess image and video file from library.
I think this is happening because of audio file are not storeded in photoLibrary, if so can anyone please tell me how can I accsess/open only audio files from device so user can have options to choose.
// below is the code I'm using for selecting media (image/video/audio)
- (void)selectingMediaFromLibraryOfType:(MEDIAUPLOADTYPE)mediaType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
switch (mediaType) {
case mediaUploadTpeAudio:
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMP3, nil]; //crashing on this line
break;
case mediaUploadTpeImage:
break;
case mediaUploadTpeVideo:
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
break;
default:
break;
}
[self presentViewController:picker animated:YES completion:NULL];
}
I have done same for image and video and it's working.
Also I want to know where files are store when you transfer/download audio file from ios to ios.
Media picker for audio is different than images and videos. You have to use MPMediaPickerController class. It functions same as UIImagePickerController class.
and implement MPMediaPickerControllerDelegate to get the selected files.

How do I enable multiple files selection while picking file using UIDocumentPickerViewController?

I'm trying to pick file from Files App using UIDocumentPickerViewController but I can't see Select button for multiple selection in picker. Why this is happening? am i doing anything wrong? Can anyone help?
Code snippet :
NSArray *arrContents = #[#"public.content",#"public.item",#"public.composite-content",#"public.data",#"public.database",#"public.calendar-event",#"public.message",#"public.presentation",#"public.contact",#"public.archive",#"public.disk-image",#"public.text",#"public.plain-text",#"public.utf8-plain-text",#"public.utf16-external-plain-​text",#"public.utf16-plain-text",#"com.apple.traditional-mac-​plain-text",#"public.rtf"];
UIDocumentPickerViewController *dvc = [[UIDocumentPickerViewController
alloc]initWithDocumentTypes:arrContents inMode:UIDocumentPickerModeImport];
dvc.delegate = self;
[self presentViewController:dvc animated:true completion:nil];
set dvc.allowsMultipleSelection = true; after initialising UIDocumentPickerViewController.

UIImagePickerController stream type used to append .MOV?

What stream is employed in iOS7 by AVCaptureMovieFileOutput in a UIImagePickerController to append video frames from the camera to it's temporary .MOV file?
A .MOV file is created in a temporary location, and then further appended to by an underlying AVCaptureMovieFileOutput object, when a user is recording a video via a presented UIImagePickerController in iOS7.
I've attempted to use symbolic breakpoints and method swizzling in order to pinpoint one of the following (but with no success). It's possible I've missed the one stream type or class that is actually being used (or that my breakpoints are setup incorrectly):
NSWriteStream
CFWriteStream
subclassed NSStream
fstream
ofstream
ostream
iostream
NSFileHandle
posix file descriptor
AVAssetWriter
AVAssertExportSession
ALAssetClass
ALAssetLibrary
This is what I am using to present the UIImagePickerViewController to record video:
#import <MobileCoreServices/MobileCoreServices.h>
-(void)startPicker{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[picker setAllowsEditing:NO];
[picker setDelegate:self];
[picker setMediaTypes:#[(NSString*)kUTTypeMovie]];
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
if (info)
{
NSURL* fileURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"%#", fileURL.path);
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
I really need the specific stream type and a way that I can prove for myself that it is being used by iOS7. Many thanks!
A way you can prove? I am not sure, but Apple favors m3u8 for streaming
https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/DeployingHTTPLiveStreaming/DeployingHTTPLiveStreaming.html

Why is the cancel button in my media picker not working?

I'm a new developer and I'm getting to know music and sound in iOS.
I've managed to make a media picker where the user can select music but when I press the cancel button, nothing happens. This is the method I'm using:
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
I tried putting an NSLog in it to see if it was actually being called and there was nothing in the console so it's not actually being called at all. Is there a reason and solution that can be concluded with this information? Have I simply missed out something or might have not done something elsewhere?
Any help would be greatly appreciated.
If the code I used for the media picker would be helpful, here it is:
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
[mediaPicker setDelegate:self];
mediaPicker.prompt = NSLocalizedString(#"text1", "text2");
[self presentViewController:mediaPicker animated:YES completion:nil];
I wonder if you need to do:
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker
{
[mediaPicker dismissViewControllerAnimated:YES completion:nil];
}
instead?
Also, set a break point within your "mediaPickerDidCancel" method and just see it the breakpoint even hits when hitting the cancel button in the picker.
In Swift :
func mediaPickerDidCancel(mediaPicker: MPMediaPickerController){
// Dismiss the picker if the user canceled
dismissViewControllerAnimated(true, completion: nil)
}

Do not compress video when I select a video

I am making Video Upload App in IOS.
I got a problem on UIImagePickerController.
That is,
When I whenever select a Movie, It compressed automatically.
I had tried every VideoQuality Options. (High, Medium, Low)
Do I use other Controller or my own Controller?
A short video(5 minutes) compression spends very long time(several minutes) on my iPhone(4S).
I think that my app supports over 10 minute video at least.
My Code are like this.
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
[picker setSourceType:sourceType];
[picker setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeMovie]];
// Video Quality Setting..
[picker setVideoQuality:UIImagePickerControllerQualityTypeHigh];
[self presentModalViewController:picker animated:YES];
}
}
- (IBAction)showLibrary:(id)sender
{
[self showImagePicker:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
}
- (IBAction)showCamera:(id)sender
{
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}

Resources