Search code examples
objective-cuiimagepickercontrollernsbundle

Migrating from NSBundle hardcoded video to allow for image picker file instead


I am new here and still getting started so bear with me on this one.

I have code that will upload a "videoTest.MOV" file that's embedded in the project. I want to change that code to upload the video that I selected from the image picker code contained in the video action below.

Thanks for any help, I am completely stumped on this one.

// Upload static file to Youtube
-(void)uploadVideoOnYouTube
{
_uploadVideo = [[YouTubeUploadVideo alloc] init];
_uploadVideo.delegate = self;
NSURL *VideoUrl = [[NSBundle mainBundle] URLForResource:@"videoTest" withExtension:@"MOV"];
NSData *fileData = [NSData dataWithContentsOfURL:VideoUrl];
NSString *title;
NSString *description;

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"'Test Video Uploaded ('EEEE MMMM d, YYYY h:mm a, zzz')"];
title = [dateFormat stringFromDate:[NSDate date]];

description = @"This is test";

[self.uploadVideo uploadYouTubeVideoWithService:self.youtubeService
                                       fileData:fileData
                                          title:title
                                    description:description];
}

// Image Picker that only shows movies, no images.
- (IBAction)video:(id)sender {

UIImagePickerController *imagePicker = [[UIImagePickerController alloc]     init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,      nil];

[self presentModalViewController:imagePicker animated:YES];
}

Solution

  • - (void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    // This is the NSURL of the video object
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    
    NSLog(@"VideoURL = %@", videoURL);
    
    [picker dismissViewControllerAnimated:YES completion:NULL];
    [self YoutubeShare:videoURL];
    }