从NSBundle硬编码视频迁移到允许图像选择器文件

时间:2017-03-03 20:57:42

标签: objective-c uiimagepickercontroller nsbundle

我是新来的,还在开始,所以请耐心等待。

我的代码会上传项目中嵌入的“videoTest.MOV”文件。我想更改该代码以上传我从下面的视频操作中包含的图像选择器代码中选择的视频。

感谢您的帮助,我完全被这个问题困扰了。

// 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];
}

2 个答案:

答案 0 :(得分:0)

将视频保存在本地所需的格式化程序中,然后将其发送到您的服务器

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"];
    BOOL success = [videoData writeToFile:tempPath atomically:NO];
    [picker dismissViewControllerAnimated:YES completion:nil];
    }

注意:未经测试

答案 1 :(得分:0)

- (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];
}