I've a UIImagePickerController in video mode; after I finish recording video and I tap on "Use" button to accept the video I use this method -(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info and inside it i want save the video in camera roll and retrieve the first frame from the video to show it in UIImageView. The code that I use is the following:
NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *url = [NSURL fileURLWithPath:tempFilePath];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.shouldAutoplay = NO;
imageView.image = [moviePlayer thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
The problem is that if I add the method UISaveVideoAtPathToSavedPhotosAlbum the app crash.
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);
where tmpFilePath is the same that I used above.
Instead if I use only one of this operation (UISaveVideoAtPathToSavedPhotosAlbum or retrieve frame) all work fine !
The console report this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'
Any ideas ? Thanks...
In your class, do you implement the following method?
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
Related
I have a UIWebView that showing text and images from web.
I want to do it like when i tap on Image in UIWebView , i want to show it in Full Screen including Orientations.
so i tested with following codes.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *URL = [request URL];
NSData *data = [[NSData alloc] initWithContentsOfURL:URL];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data]];
GGFullscreenImageViewController *vc = [[GGFullscreenImageViewController alloc] init];
vc.liftedImageView = imageView;
[self presentViewController:vc animated:YES completion:nil];
return NO;
}
else
{
return YES;
}
}
It doesn't work and showing error when i tap image in UIWebView.
2014-03-12 13:59:40.397 MMSP[1368:a0b] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; nan nan]'
*** First throw call stack:
Is there anyway to do like i said above?
a) I think you should set the frame for GGFullscreenImageViewController
b) Generally (not having to do with your crash), i think you should not use [[NSData alloc] initWithContentsOfURL:URL]; to load the image at this point. On clicking a link, it will wait until the image has downloaded, and then show it, resulting in a 'lag' for your user.
Instead, just hand over the URL to your GGFullscreenImageViewController, the view controller and have it display an activity indicator until it has downloaded the image.
If you already have a UIImageView setup on your GGFullscreenImageViewController then why not just create the UIImage and assign, instead of creating a new UIImageView. The image view instance in liftedImageView is lost when you assign newly created instance.
Just do this,
NSData *data = [[NSData alloc] initWithContentsOfURL:URL];
GGFullscreenImageViewController *vc = [[GGFullscreenImageViewController alloc] init];
vc.liftedImageView.image = [UIImage imageWithData:data];
Ideally, you should pass the image url to the GGFullscreenImageViewController by providing initWithUrl: method. Do the downloading of image asynchronously or you could use open source code which does this, ex: SDWebImage.
Hope this helps!
Hi, I'm new to the iOS app development I have created an app with two ViewController for the the second controller have created on class in called video controll view. Everything is fine but when I click the play I'm getting warning like this I don't what is this can anyone please help me on that I'm stuck here for long time.
2013-12-25 10:10:12.890 politicalapp[346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
This is the code I have put for the video player:
- (IBAction)play:(UIButton *)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d" ofType:#"mp4"]];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL: url];
[self presentMoviePlayerViewControllerAnimated:player];
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;[player.moviePlayer play];
player = Nil;
}
#end
Your problem is that pathForResource is returning nil. There can be a number of causes of this. Try changing it to:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d.mp4" ofType:nil]];
If that doesn't solve it, just search the multiple of questions on stackoverflow named "Path for resource returns nil" and trouble shoot based on the various issues already discussed.
This question already has answers here:
How do I get an image from the iOS photo library and display it in UIWebView
(5 answers)
Closed 9 years ago.
i have this code in my program but it seems to be crashing the program and i cant figure out why.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Get Image URL from Library
NSURL *urlPath = [info valueForKey:UIImagePickerControllerMediaURL];
NSString *urlString = [urlPath absoluteString];
NSLog(urlString);
NSURL *root = [[NSBundle mainBundle] bundleURL];
NSString *html;
html = #"<img src='";
html = [html stringByAppendingString:urlString];
html = [html stringByAppendingString:#"' />"];
[MemeCanvas loadHTMLString:html baseURL:root];
[picker dismissViewControllerAnimated:YES completion:^{}];
}
It seems to be caused around the section where i append the asset-library address (urlString) to the the html string. i dont know why this would give a problem.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'
Any help is appreciated.
Thanks in advance.
Does this link help? It explains that you will not get a URL for images but an image object instead.
UIImagePickerControllerMediaURL always nil for a photo
I guess you need to save the image in documents directory and then display it in the webview.
I have an app where I can shoot a video and then store it in core-data with some other data. It's stored as Transformable and "Store in External Record File". I get the video clip into an object called movie like this;
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
movie = [info objectForKey:UIImagePickerControllerEditedImage];
Where I get stuck is to get a thumbnail from the movie. Using MPMoviePlayerController I have to have an URL, but the movie isn't stored anywhere yet. Plus finding the URL from the core-data is a mystery as well.
The closest help I can find here is Getting a thumbnail from a video url or data in iPhone SDK . But I get caught out on the URL issue.
I am saving it to core-data like this;
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newMedia = [NSEntityDescriptioninsertNewObjectForEntityForName:#"Media" inManagedObjectContext:context];
[newMedia setValue:#"Video Clip " forKey:#"title"];
[newMedia setValue:now forKey:#"date_time"];
[newMedia setValue:movie forKey:#"movie"];
[newMedia setValue:[self generateImage] forKey:#"frame"];
I would be grateful if there is someone out there that can give me a pointer.
I used like this in my app
- (UIImage *)imageFromMovie:(NSURL *)movieURL atTime:(NSTimeInterval)time {
// set up the movie player
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
initWithContentURL:movieURL];
mp.shouldAutoplay = NO;
mp.initialPlaybackTime = time;
mp.currentPlaybackTime = time;
// get the thumbnail
UIImage *thumbnail = [mp thumbnailImageAtTime:time
timeOption:MPMovieTimeOptionNearestKeyFrame];
// clean up the movie player
[mp stop];
[mp release];
return(thumbnail);
}
used like
imageView.image = [self imageFromMovie:fileURL atTime:10.0];
To get thumbnail from movie...
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if ([[info objectForKey:#"UIImagePickerControllerMediaType"] rangeOfString:#"movie"].location!=NSNotFound)
{
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:#"UIImagePickerControllerMediaURL"]];
theMovie.view.frame = self.view.bounds;
theMovie.controlStyle = MPMovieControlStyleNone;
theMovie.shouldAutoplay=NO;
UIImage *imgTemp = [theMovie thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionExact];
}
}
You can get your movie URL like this and then use this URL to get thumbnail using MPMoviePlayerController.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
. .. .
.. ..
}
I got a big performance issue using UIImagePickerController and saving the image on disk. I can't figure out what I am doing wrong. Here is my code:
- (void)imagePickerController:(UIImagePickerController *)pick
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
iPixAppDelegate *delegate = (iPixAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate addPicture:imageData];
}
The addPicture method creates a new picture object that is initialized this way:
- (Picture*) initPicture:(NSData*)dat inFolder:(NSString*)pat {
self.data = dat;
NSDate *d = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyyy-mm-dd hh-mm-ss"];
self.name = [[formatter stringFromDate:d] stringByAppendingString:#".png"]; //The name by default of a picture is the date it has been taken
[formatter release];
self.path = [pat stringByAppendingPathComponent:self.name];
if(![self fileExistsAtPath:self.path]){
[self.data writeToFile:self.path atomically:YES];
}
return self;
}
The UIImagePickerController is quite fast but the program becomes very slow when I save picture on the disk.
Any idea on what I am doing wrong?
I had a similar issue. The way I got round it was to handle the image from the picker in a seperate thread. My problem was the main thread handling my app/UI was crashing out when trying to close the picker and handle the image:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
NSLog(#"picker did finish");
[NSThread detachNewThreadSelector:#selector(useImage:) toTarget:self withObject:image];
}
Your problem might be due to you taking the original image.
The original image from the camera has a resolution of around 1200x1400, which is a lot of memory and will cause the device to crash if you try making a picture out of it (it will run out of memory).
I would suggest resizing the image to be smaller (the native 320x480).