简体   繁体   中英

How to share .avi video on iOS

I'm currently working on an IP Camera project. One of the features is that you can download and view recordings from the cameras. You get an url from the camera, download the file and play it using VLC from within the app. However, these files are in .avi which is not supported by iTunes. Is it still possible to share .avi files? When I use the following code:

NSString *urlToDownload = [NSString stringWithFormat:@"%@localhost:%@%@", self.activeRecording.urlProtocol, self.activeCamera.localPort, self.activeRecording.urlQuery];
NSString *fullPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[urlToDownload lastPathComponent]];
NSURL *videoUrl = [NSURL URLWithString:fullPath];
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[videoUrl] applicationActivities:nil];
[self presentViewController:self.activityViewController animated:YES completion:nil];

The url is correct as I can use it to watch the recording. When the share menu opens, it only shows "other" as an option. I'd like to be able to share the video on Facebook and stuff, but at the very least be able to email the video using the share button. Can anyone help me?

tl;dr: Want to share .avi video, doesn't work.

My current solution is to only allow this to be shared over email with the following code:

NSString *urlToDownload = [NSString stringWithFormat:@"%@localhost:%@%@", self.activeRecording.urlProtocol, self.activeCamera.localPort, self.activeRecording.urlQuery];
NSString *fullPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[urlToDownload lastPathComponent]];
NSData *video = [NSData dataWithContentsOfFile:fullPath];

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:[NSString stringWithFormat:NSLocalizedString(@"%@ recording", @"-name- recording"), self.activeRecording.name]];

[picker addAttachmentData:video mimeType:@"video/avi" fileName:@"recording.avi"];

[self presentViewController:picker animated:YES completion:nil];

If anyone could find a better solution, that'd be awesome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM