Picking video from application and copy them in document directory - iphone

I was using UIImagePickerController to select the video files from Image Gallery of IPhone using
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
and that code is working fine and picker shows me all available videos in Gallery but the problem is that UIImagePickerController do not shows all videos of IPhone like videos on Video folder of Iphone and also the synched videos on IPhone. In short it only shows video recorded from Iphone only. But my requirement is to show all videos in Iphone and getting their path so that I can write them using FileManager.
I also tried using
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"AddSongsPrompt", #"Prompt to user to choose some songs to play");
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated:YES];
[self presentModalViewController: picker animated: YES];
[picker release];
But it also shows me music files of Iphone not video.
Please some one has any idea how to do this?

try initWithMediaTypes:MPMediaTypeAnyVideo instead of initWithMediaTypes: MPMediaTypeAnyAudio
also see this link for more information, MPMediaItem_ClassReference

Related

Imagepicker for AVCaptureSession

I implemented code for taking picture using AVCaptureSession. And i have button to pick image from Gallery. So, i need to use UIImagePickerController for picking image from gallery.
Is it possible to use UIImagepicker for picking Gallery and AVCaptureSession for taking picture. If i use this inside same app, appstore reject app or not?
Sure. You want to create your UIImagePickerController with a sourceType of UIImagePickerControllerSourceTypePhotoLibrary:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
I can't imagine that Apple would reject you for doing this in the same app that you're using AVCaptureSession - they're providing these classes to do exactly what you're proposing, after all.

Video orientation converted from Portrait to Landscape after uploading to server : iPhone camera

I have captured a video in portrait mode from my application. When I uploaded the same and checked on server, the video was converted to Landscape automatically.
I am using folowing code to start capturing the video
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.videoMaximumDuration = 3.0;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
[self presentModalViewController:picker animated:YES];
Please advice, I was having same issue while taking image from camera, for which I got help from this post but for video I am not getting any proper idea.

How to record video in iPhone using Objective-C?

I have a map application in which there is a button named video. If a user clicks on the video button he can record video at any location he like and simultaneously play the video.
How can I do this? My code is as follows:
-(IBAction)video:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){ NSLog(#"device not supported"); return; } picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo]; picker.videoQuality = UIImagePickerControllerQualityTypeHigh; [self presentModalViewController:picker animated:YES]; }
From Apple Programming guides
Starting in iPhone OS 3.0, you can
record video, with included audio, on
supported devices. To display the
video recording interface, create and
push a UIImagePickerController object,
just as for displaying the
still-camera interface.
To record video, you must first check that the camera source type
(UIImagePickerControllerSourceTypeCamera)
is available and that the movie media
type (kUTTypeMovie) is available for
the camera. Depending on the media
types you assign to the mediaTypes
property, the picker can directly
display the still camera or the video
camera, or a selection interface that
lets the user choose.
Using the UIImagePickerControllerDelegate
protocol, register as a delegate of
the image picker. Your delegate object
receives a completed video recording
by way of the
imagePickerController:didFinishPickingMediaWithInfo:
method.
On supported devices, you can also pick previously-recorded videos from a
user’s photo library.
For more information on using the image picker class, see
UIImagePickerController Class
Reference. For information on trimming
recorded videos, see
UIVideoEditorController Class
Reference and
UIVideoEditorControllerDelegate
Protocol Reference.
Once you have the video in your UIImagePickerController delegate you can then save it to your app's documents directory using standard file operations.

How to import music file from iphone music library to iPhone App

In MY iPhone App I am able to browse iphone Music Library
even I am importing media file name to my app music file list
but while running app next time i am not getting media file name which I imported previously
In My App i am importing songs from one folder "MusicSampler" which is in my APP Folder now On buttonclick I am opening iPod music Library and selecting song (Using mediaPicker) which is added to my song list at buttom, now next time when i am opening my App it loads the all songs from "musicSampler" folder but this time the new added songs previously from iPod-Library are not showing
what I should do to save imported song from iPod music library to my iphone app( either by adding music file to my "MusicSampler" or something else)
Please Help and Suggest
Thanks
Here is an example:
http://www.subfurther.com/blog/2010/07/19/from-iphone-media-library-to-pcm-samples-in-dozens-of-confounding-potentially-lossy-steps/
In sum, you should use CoreAudio or AV Foundation to save mp3 from iPhone Media Library.
I hope that it helps you.
OPEN Music Library of Phone
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES;
[self presentViewController:mediaPicker animated:YES completion:nil];
Delegate are
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
[self dismissViewControllerAnimated:YES completion:nil];
MPMediaItem *item = [mediaItemCollection representativeItem];
player=[[AVAudioPlayer alloc]initWithContentsOfURL:[item valueForProperty:MPMediaItemPropertyAssetURL] error:nil];
[player play];
}
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
[self dismissViewControllerAnimated:YES completion:nil];
}

picking and uploading the video for iphone 3g ios 4

I want to upload a video from iPhone to a server somewhere.
I have found this useful question here for uploading a video on the server from iPhone.
The only problem here is picking the video. The code is using uiimagepickercontroller to pick up the video and I have a 3g phone which has not video in its photos app. I can't even put a video in it . I have a video only in iTunesU . Currently I am using following snippet for uiimagepickercontroller .
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Error accessing photo library"
message:#"Device does not support a photo library"
delegate:nil
cancelButtonTitle:#"Drat!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
So I have to ask that is it necessary to pick a video from uiimagepickercontroller and if so how can I do so with my iPhone 3G .
Please tell me if the question is not readable.
Thanks .
There is no video support for 3G that I am aware of.
In order to make it work (you could simulate it) you need to pass a mediaType of 'kutTypeMedia', which errors as not available on your device.
'If' you want to test, you can copy a video from the bundle, into your Camera Roll and test on the simulator.
Something like this to copy the video from the bundle to your camera roll:
Copy a video file from your bundle and save it to the album as below!
"Bundle Path :
(Where APPLCIATIONGUID and user are dynamic and depend on the logged on user and the applicationGUID)
'/Users/user/Library/Application Support/iPhone Simulator/4.0/Applications/APPLICATIONGUID/Documents'
Where APPLICATIONGUID is the GUID associated with your particular project. You can confirm that you are in the right folder by looking for the appropraite .app file.
Note:// I don't believe that this will work with a MOV but have tried nothing but a .m4v.
NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:#"Documents/VID_0001.m4v"]];
NSString *videoFilepath = [[NSBundle mainBundle] pathForResource:#"VID" ofType:#"m4v"];
NSLog(#"Filepath is: %#", videoFilepath);
//test video can save to the photos album first - code missing
UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);*
Once this has been done - videos are available in your photo album for selecting should you be setting up your UIImagePickerController with the correct media type.
This is the only option I see that you have to work with Video without a 3GS.