【问题标题】:How to display all the videos along with photos from camera album in documents?如何在文档中显示所有视频以及相册中的照片?
【发布时间】:2013-09-18 05:05:31
【问题描述】:

我是 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];

}

【问题讨论】:

    标签: iphone ios cocoa-touch alassetslibrary


    【解决方案1】:

    编辑:点击新链接。

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

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

    【讨论】:

    • 在您的代码中,您已经硬编码了视频文件的 URL。但我想访问那些从手机摄像头拍摄的视频。
    • 我之前已经编辑了链接。此代码将获取您相册中所有可用的视频。然后,如果您想扫描指定的视频,您必须根据您的需要编辑相同的代码需要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多