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

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.

Related

UIImagePickerController trim controls not showing

I've been unable to get the trim controls to appear when capturing an iOS movie.
Here's my code:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(__bridge NSString *)kUTTypeMovie, (__bridge NSString *)kUTTypeImage];
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
Additionally, I'm capturing the reply with imagePickerController:didFinishPickingMediaWithInfo:.
From searching StackOverflow I'm aware that I need to actually trim the video myself. That doesn't seem too difficult, but while I get the image picker and can capture a video I can't get the trim controls to appear! What am I missing?
My mistake was just in using video samples that were too short. They need to be over a certain length before the trimming tools will appear.

ABPeoplePickerNavigationController and UIImagePickerController not displaying correctly on ipad iOS7

When I try use "ABPeoplePickerNavigationController" or "UIImagePickerController", in most cases it won't load up correctly. It will show part of the screen (transparent) starting in the middle of the screen in iOS 7 (ipad) for both simulator and device (screenshot below). In iOS 8 everything works correctly.
This is the code I use for ABPeoplePickerNavigationController:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
self.preserveCurrentEntity = YES;
[self presentViewController:picker animated:NO completion:nil];
UIImagePickerController will break just for picking videos, but work for everything else, this is the code I use:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
switch (buttonIndex) {
case ImagePickerModeCamera:
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case ImagePickerModeAlbum:
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
default:
break;
}
imagePicker.delegate = self;
NSMutableArray *mediaType = [[NSMutableArray alloc] init];
switch (self.actionSheetType) {
case ActionSheetTypeImage:
[mediaType addObject:(NSString*)kUTTypeImage];
break;
case ActionSheetTypeVideo: {
[mediaType addObject:(NSString*)kUTTypeMovie];
[mediaType addObject:(NSString*)kUTTypeVideo];
imagePicker.allowsEditing =NO;
}
break;
default:
break;
}
imagePicker.mediaTypes = mediaType;
[self presentViewController:imagePicker animated:NO completion:nil];
This is what happens in iOS7 when loading ABPeoplePickerNavigationController:
This is what happens in iOS8 when loading ABPeoplePickerNavigationController:
What is the solution to fix this?
Looks like I found the solution to my problem.
I have a root view controller that has two xibs, one for iPad and one for iPhone. It seems my iPad one was causing the trouble even though they were very similar (just one was larger). I couldn't figure out why.
I just use the iPhone one now and make sure it resizes correctly on iPad and everything is working correctly.
I have the same problem like you, but after wasting some time I got some post, that what may be the reason in your case.
iPhone Library does not work on the iOS Simulator in special case of picking Vedio
Referred Post for my solution. and worked for me.
Update on it, if you still facing problem, I can post my code to help you.
HTH, Enjoy Coding !!

How to select multiple video from camera roll and photo Gallery?

I want to upload multiple video to server using ASIHttDataFormRequest.For selecting video ,I am using ImagePickerViewController But it doesn't give the option to select multiple video.
Bellow is the code, which is used to open imagePicker and but unable to select multiple video.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
Please help me by giving some clue or code. Thanks in Advance
Use this sample
https://github.com/B-Sides/ELCImagePickerController
For video multiple selection refer
Use ELCImagePickerController to pick video
Hope it helps you..
Here is the library to take a photo or select from library: https://github.com/fulldecent/FDTake
This works great so far for photos. Video is in progress.

Programmatically take X amount of pictures

I am trying to implement a feature of taking X amount of pictures programmatically after entering a UIViewController for both the iPhone and iPad. I looked into UIImagePickerController but I do not want to present the camera controls and have the user hit a button to capture only one photo. Is there a way to capture X amount of photos once entering a UIViewController and storing all the photos in the end for future reference in one go?
Edit:
-(void)viewDidAppear:(BOOL)animated
{
// Create image picker controller
picker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
// Set source to the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
picker.delegate = self;
// Allow editing of image ?
picker.allowsEditing = NO;
//picker.showsCameraControls = NO;
// Show image picker
[picker animated:YES completion:nil];
}
straight away with takePicture you can not take multiple snaps, for that you have to use some video recording and get snap out of it for particular frame or time, for you more reference you can use this apple documentation for bulk snaps AVFoundation Programming Guide
You can try something like this:
int numberOfPhotos = 3; // Number of photos you want to take.
for ( int i = 0; i < numberOhPhotos; i++ )
{
// Note that you should use some sort of a pause in between each photo.
[picker takePicture];
}

How to import video from library in iPhone into my application?

I know that this question been asked before, but I'm getting an error while I'm running this code for picking video.
-(void)video
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,nil];
[self presentModalViewController:imagePicker animated:YES];
}
This code taking me to a window where video should appear. But the window is blank. The message showing is "No Videos you can sync photos and videos onto your iPod.............albums and videos" . I know that this message shows when there is no videos in video library. But I import lot of videos and still showing this error.
You should take a look at this "HowTo" : http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios. It helped me a lot.
You will only need the first part.

Resources