从NSBundle硬编码视频迁移,以允许图像选择器文件
问题描述:
我在这里是新的,并且仍然开始,所以在这一点上我忍受。从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];
}
答
- (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];
}
答
保存在本地视频什么的,你所需要的甲,你可以发送到您的服务器
- (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];
}
注:未测试