• iOS7编程Cookbook中例15.8中一个小问题


    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处.
    假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;)


    该书的15.8样例标题为Editing Videos on an iOS Device,代码的功能为创建一个UIImagePickerController视图让用户从照片库选择一个视频文件,然后在UIVideoEditorController视图中编辑该视频,最后得到编辑后视频文件的路径.

    非常好非常easy,可是在实际执行代码中发现当UIImagePickerController返回后,在imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary*)info回调方法中获取不到被选择视频的URL路径:

    NSString *mediaType = info[UIImagePickerControllerMediaType];
        if ([mediaType isEqualToString:(__bridge NSString*)kUTTypeMovie]) {
            _videoURLToEdit = info[UIImagePickerControllerMediaURL];
        }

    即执行后的_videoURLToEdit总为nil,即使前面的资源类型是正确的:为kUTTypeMovie类型.

    网上搜了一下,发现非常多人说在iOS9里面都是这样,包括Stack OF里面也是如此.但不怎么相信此说法…

    后来到Apple SDK中查找info字典的解释:

    info
    A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked. The dictionary also contains any relevant editing information. The keys for this dictionary are listed in Editing Information Keys.

    能够看到其全部key的解释:

    NSString *const UIImagePickerControllerMediaType;
    NSString *const UIImagePickerControllerOriginalImage;
    NSString *const UIImagePickerControllerEditedImage;
    NSString *const UIImagePickerControllerCropRect;
    NSString *const UIImagePickerControllerMediaURL;
    NSString *const UIImagePickerControllerReferenceURL;
    NSString *const UIImagePickerControllerMediaMetadata;
    NSString *const UIImagePickerControllerLivePhoto;

    注意看当中包括一个UIImagePickerControllerReferenceURL枚举,其说明称该key的值为原始资源的URL.而UIImagePickerControllerMediaURL里的值是当原始资源被改动后的URL.

    我们前面总是返回nil,是由于我们没有改动原始资源,所以总为空值.

    我们简单的将代码改动例如以下就可以:

    if ([mediaType isEqualToString:(__bridge NSString*)kUTTypeMovie]) {
            _videoURLToEdit = info[UIImagePickerControllerMediaURL];
            if (!_videoURLToEdit) {
                _videoURLToEdit = info[UIImagePickerControllerReferenceURL];
            }
        }
  • 相关阅读:
    [HEOI2014]人人尽说江南好 博弈论
    [HNOI2014]江南乐 博弈论
    [SDOI2011]黑白棋 kth
    [NOI2011]兔兔与蛋蛋游戏 二分图博弈
    [JSOI2009]游戏 二分图博弈
    口胡:[HNOI2011]数学作业
    【POJ】【2068】Art Gallery
    【CTSC 2015】&【APIO 2015】酱油记
    【BZOJ】【4052】【CERC2013】Magical GCD
    【BZOJ】【2750】【HAOI2012】Road
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7261401.html
Copyright © 2020-2023  润新知