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.
Related
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
Posted this on Apple with no luck, but now that the iOS 6 NDA is up, hoping more eyes will see it here.
I am attempting to modify an app to only allow a user to select music that has been downloaded locally. I have the following code under iOS 6 GM:
MPMediaPickerController* mpc = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
mpc.allowsPickingMultipleItems = YES;
mpc.modalPresentationStyle = UIModalPresentationCurrentContext;
mpc.showsCloudItems = NO;
[self presentViewController:mpc animated:YES completion:nil];
From the documentation:
The default behavior for a media item picker is YES, which means the
the picker shows available iCloud items. A media item is considered an
iCloud item if it is available via iTunes Match and is not already
stored on the device.
I take this to mean that if iTunes Match is enabled, only items that have been downloaded to the device will show in the picker, however I always see the entire iTunes Match library. I filed a radar for this, because it seems like a serious bug. If anyone can tell me otherwise, I'd love to know what I'm missing here.
This seems to be an OS problem.
Using picker.showsCloudItems = NO; correctly shows fewer songs, instead of the whole list... The songs listed there are songs that either were manually downloaded in the Music app or songs that were streamed and therefore cached.
The problem, at least in my case, is dealing with the cached ones.
If I select a song that was manually downloaded the value of MPMediaItemPropertyIsCloudItem is NO, which is correct. I can also access the asset's URL through the MPMediaItemPropertyAssetURL property.
On the other hand, selecting a song that was cached returns YES on MPMediaItemPropertyIsCloudItem and nil on MPMediaItemPropertyAssetURL, making the song virtually useless to me.
Sorry I don't have an actual answer but I don't have enough reputation to simply comment.
Hope my 2 cents help somehow, but it truly seems to me that this issue can only be resolved by Apple in a future update.
A better solution to test if an item comes from iCloud in the didPickMediaItems delegate:
MPMediaItem *selectedItem = [selectedItems objectAtIndex:0];
if (![[selectedItem valueForProperty:MPMediaItemPropertyIsCloudItem] boolValue])
You don't really need to play it, it is more efficient to use the embedded property in the MPMediaItem.
I had this same problem. Although I was unable to hide the items, here's a good workaround that I used to prevent people from being able to select them. Inside didPickMediaItems, you should temporarily load it into an AVPlayerItem and then just check the validity of that item like so:
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
MPMediaItem *selectedItem = [[mediaItemCollection items]objectAtIndex:0];
NSURL *tempURL = [selectedItem valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [[AVPlayerItem alloc]initWithURL:tempURL];
if(playerItem.loadedTimeRanges==NULL)
{
UIAlertView *alert=[[[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Invalid Song Choice",NULL) message:NSLocalizedString(#"Please choose a song that is local to your phone.",NULL) delegate:self cancelButtonTitle:NSLocalizedString(#"Okay",NULL) otherButtonTitles:nil]autorelease];
[alert show];
[playerItem release];
}
else
{
NSLog(#"Your good to go...do whatever you want with the local song");
}
}
It appears to be fixed in iOS 7.
The following code works; iCloud items are not showing:
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.showsCloudItems = NO;
I am building an iPhone app that can save email attachments. I would like to be able to view the files from inside the application as well. I need to be able to view as many kinds of files as possible: .txt, .pdf, .png, .jpeg., .doc, .xls, etc.
The files will reside inside of my application's documents folder. What is the best solution for this? My first thought is to convert my file-paths to URLs and load them in a UIWebView, but I'm not sure if this is the best way, or if it will handle all those file types. Any thoughts?
The way Apple's own Mail app does this is with the QuickLook framework. I'd suggest you do the same. QLPreviewController does all the heavy lifting for you. You can also use UIDocumentInteractionController; this is still using QuickLook behind the scenes to generate the preview.
The UIWebView is the best way to show this kind of file.
Alternatively you can try to read the document in an other app with this code:
UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController interactionControllerWithURL:document.documentURL] retain];
interactionController.delegate = self;
BOOL canOpenDocument = [interactionController presentOpenInMenuFromRect:CGRectMake(365, 200, 300, 400) inView:self.view animated:YES];
if(!canOpenDocument) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Your phone can't read this kind of file, please install an app from appstore for that" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
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.
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];
}