Hi guy's
I need to get the duration of the video capture and to set the image for the thumbnail of captured video.
Please guy's can anyone help how to get rid of this?
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Success! Received %d bytes of file data", [currentFileDataContainer length]);
// urlStr = [[NSString alloc]initWithData:currentFileDataContainer encoding:NSASCIIStringEncoding];
printf("newUrlStr====%s",[newUrlStr UTF8String]);
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 440)];
[myView addSubview:webView];
webView.backgroundColor = [UIColor blueColor];
[webView loadHTMLString:[self getVideo] baseURL:[NSURL URLWithString:@"http:bluepal.com"]];
webView.delegate = self;
self.view = myView;
}
-(NSString *)getVideo
{
NSString *htmlString = @"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 94\"/></head><body style=\"background:#000;margin-top:0px;margin-left:0px\"><div><object width=\"90\" height=\"70\"><embed src=\"";
htmlString = [htmlString stringByAppendingString:newUrlStr];
htmlString = [htmlString stringByAppendingString:@"\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"400\"></embed></object></div></body></html>"];
printf("\n htmlString.......%s",[htmlString UTF8String]);
return htmlString;
}
- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[[UIImagePickerController alloc] init]autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
picker.delegate = self;
picker.showsCameraControls=YES;
picker.allowsEditing = NO;
UIView *overlayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
picker.cameraOverlayView = overlayView;
[controller presentModalViewController:picker animated:YES];
}
return YES;
}
- (NSData *)generatePostDataForData:(NSData *)uploadData
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddhhmmss"];
NSString *fromDateString=[dateFormatter stringFromDate:[NSDate date]];
// Generate the post header:
NSString *fileNameString=@"";
fileNameString=[fileNameString stringByAppendingString:fromDateString];
[fileNameString stringByAppendingString:@".3gp"];
NSString* finalPostString=[NSString stringWithFormat:@"--AaB03x\r\nContent-Disposition: form-data; name=\"uploadedfile\"; filename=\"%s\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n\r\n",[fileNameString UTF8String]];
NSString *post = [NSString stringWithCString:[finalPostString UTF8String] encoding:NSASCIIStringEncoding];
NSData *postHeaderData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
// Generate the mutable data variable:
NSMutableData *postData = [[NSMutableData alloc] initWithLength:[postHeaderData length] ];
[postData setData:postHeaderData];
// Add the video:
[postData appendData: uploadData];
// Add the closing boundry:
[postData appendData: [@"\r\n--AaB03x--" dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
// Return the post data:
return postData;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
printf("\n mediaType = %s",[mediaType UTF8String]);
if ([mediaType isEqualToString:@"public.movie"])
{
NSLog(@"got a movie");
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
[self post:webData];
//[webData release];
[picker dismissModalViewControllerAnimated:YES];
}
}
- (void)post:(NSData *)fileData
{
NSLog(@"POSTING");
// Generate the postdata:
NSData *postData = [self generatePostDataForData: fileData];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
// Setup the request:
NSMutableURLRequest *uploadRequest = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://123.237.186.221:8080/upload/videoUpload.jsp"] cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 30 ] autorelease];
[uploadRequest setHTTPMethod:@"POST"];
[uploadRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[uploadRequest setValue:@"multipart/form-data; boundary=AaB03x" forHTTPHeaderField:@"Content-Type"];
[uploadRequest setHTTPBody:postData];
// Execute the request:
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:uploadRequest delegate:self];
if (conn)
{
// Connection succeeded (even if a 404 or other non-200 range was returned).
NSLog(@"sucess");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Got Server Response" message:@"Success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
// Connection failed (cannot reach server).
NSLog(@"fail");
}
}
Thanks in advance, Monish.