0

我是iOS开发的新手。我正在尝试从我的应用程序文档目录中的相册中获取所有照片和视频,然后尝试压缩它们。我只能获取照片,但不能获取视频。请告诉我如何获取视频。这就是我的代码查找照片的方式。我也尝试使用 MediaPlayer 和 MobileCoreServices 框架。但它不起作用。请帮助我提供适合我当前代码的代码。

- (void) imagePickerController:(RImagePickerController *)imagePickerController didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSArray *rootDocumentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
rootDocumentsDirectory = [rootDocumentPath objectAtIndex:0];
selectedImagesPath = [rootDocumentsDirectory stringByAppendingString:@"/Selected Images"];
[[NSFileManager defaultManager]createDirectoryAtPath:selectedImagesPath withIntermediateDirectories:NO attributes:nil error:nil];

if (imagePickerController.allowsMultipleSelection)
{
    mediaInfoArray = (NSArray *)info;
    for (i =0; i<mediaInfoArray.count ; i++)
    {
       NSData *data = UIImageJPEGRepresentation([[mediaInfoArray objectAtIndex:i] objectForKey:@"UIImagePickerControllerOriginalImage"], 1.0);
        NSString *fileNameCount = [NSString stringWithFormat:@"%@/Image%d.png",selectedImagesPath,i];
        [data writeToFile:fileNameCount atomically:YES];
    }
    NSLog(@"Selected %d photos", mediaInfoArray.count);

}
   NSDictionary *mediaInfo = (NSDictionary *)info;
   NSLog(@"Selected: %@", mediaInfo);


[self dismissViewControllerAnimated:YES completion:NULL];

}
4

1 回答 1

0

编辑: 按照新链接。

您可以使用此示例代码从相册中获取所有视频:这里

然后您将获得一系列视频。只需根据您的需要使用它们。

于 2013-09-18T05:54:21.650 回答