Saving video with UIImagePickerController

In my application, the user can record video using the UIImagePickerController, and I need to save it to disk for later use. I got the path from the information dictionary, and I'm going to save it in the document directory, but the problem I am facing is that the URL passed in the dictionary is just a URL, not a file path, When I convert it to a string using absoluteString and pass this as the source path to the file manager, it does not say that the source file was not found.

Old path: file: //localhost/private/var/mobile/Applications/77B4D2B8-DE12-4643-82F0-2ECC948E4DBC/tmp/capture/capturedvideo.MOV

New path: /var/mobile/Applications/77B4D2B8-DE12-4643-82F0-2ECC948E4DBC/Documents/video1.mov

There should be an easy way to convert my URL into what the file manager can handle. I assume that I can’t just leave all the videos in the tmp directory, should they be saved in the document directory if I want them to support them correctly?

It’s also not really connected, but how can I get a thumbnail of this video to display in a table?

+3
source share
2 answers

There should be an easy way to convert my URL into a file that a file manager can handle.

You are right - there is an easy way, it is just buried in the documentation:

NSString *myPath = [myUrl path];

From the docs for the method path:


URL. RFC 1808, nil. isFileURL YES, NSFileManager NSPathUtilities. , .

+5
NSData *imageData = [NSData dataWithContentsOfURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];


NSString *tempPath = [NSString stringWithFormat:@"%@/Documents/%@.mp4",NSHomeDirectory(),dateStr];

  [imageData writeToFile:tempPath atomically:NO];
-2

Source: https://habr.com/ru/post/1722848/


All Articles