A small problem in the iOS7 programming Cookbook example 15.8

Source: Internet
Author: User

A small problem in the iOS7 programming Cookbook example 15.8

The title of the 15.8 example in this book is Editing Videos on an iOS Device. The code function is to create a UIImagePickerController view that allows users to select a video file from the photo gallery and then edit the video in the UIVideoEditorController view, finally, get the path of the edited video file.

It is very easy, but in the actual running code, it is found that when UIImagePickerController returns, in the imagePickerController :( UIImagePickerController) Picker didFinishPickingMediaWithInfo :( NSDictionary

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

That is, after the execution, the _ videoURLToEdit is always nil, even if the previous resource type is correct: it is of the kUTTypeMovie type.

I searched the internet and found that many people say this is true in iOS9, including the Stack OF. But I don't quite believe this...

Then go to the Apple SDK to find the description of the info dictionary:

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.

We can see the explanation of all its keys:

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

Note that there is a UIImagePickerControllerReferenceURL enumeration, which indicates that the key value is the URL of the original resource. The value in UIImagePickerControllerMediaURL is the URL after the original resource is modified.

We always return nil because we have not modified the original resource, so it is always null.

We can simply modify the Code as follows:

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.