【问题标题】:How to take video from gallery like image inside application in ios如何从图库中获取视频,例如ios中应用程序内的图像
【发布时间】:2013-12-23 05:55:26
【问题描述】:

在我的应用程序中,我需要从模拟器中获取视频,我需要上传到服务器。任何人都可以帮助我。请尽快提供任何解决方案。

感谢和问候 T.swathi

【问题讨论】:

标签: ios iphone ios5 ios6 ios7


【解决方案1】:

首先,创建一个 UIImagePickerController

在您的类中,您需要实现 UIImagePickerControllerDelegate 协议并将其连接到选取器上的委托属性。一旦用户选择了某些内容,您应该能够从 didFinishPickingMediaWithInfo 中获取所选媒体的位置。

//检查不在模拟器中的iOS设备

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // this is the file system url of the media
    NSURL* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];

    // TODO: read in data at videoUrl and write upload it to your server
}

【讨论】:

  • imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = 自我; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,nil];这个委托方法没有调用然后我创建 UIImagepicker 的方式如下
  • 你在 .h 文件中声明你的委托
  • 使用这个委托
  • 我在单击照片后在图像中使用了两个代表它 vl 调用此方法 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 选择视频后它不会调用我面临的问题的方法
  • @user3092286 如果您声明了委托和分配。然后,当您从图库中选择任何项目时,必须调用它。调试你的代码,看看到底是什么问题。
【解决方案2】:

使用此功能可能会有所帮助

-(void)selectVideoButtonClicked:(id)sender{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType =    UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,      nil];
    [self presentViewController:imagePicker animated:YES completion:nil];
 }

并委托“UIImagePickerControllerDelegate”并导入框架并使用委托函数从库中选择视频

MobileCoreServices.framework 首先导入到项目中,然后导入到文件 CoreServices/CoreServices.h

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    // Handle a movie capture
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
        == kCFCompareEqualTo) {
        NSString *moviePath = [[info objectForKey:  UIImagePickerControllerMediaURL] path];
        NSLog(@" Video Path %@",moviePath);
        NSString *fileName = [[NSString alloc]init];

        //If you wants get File Name Then you can use this
        if ([moviePath rangeOfString:@"//"].location != NSNotFound) {
            NSString *separatorString = @"//";
           NSArray *disSplit = [moviePath componentsSeparatedByString:separatorString];
            fileName = disSplit[1] ;
            // [self videoUploadingDirect:moviePath];
        }

        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
            UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
            }
    }
    [self dismissViewControllerAnimated:YES completion:nil];

}

谢谢:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多