【问题标题】:display all videos stored in document directory显示存储在文档目录中的所有视频
【发布时间】:2012-07-08 14:08:59
【问题描述】:

我将照片库中的视频存储在我的文档目录中。现在我想显示存储在我的文档目录中的所有视频.. 但我不知道它怎么可能??? 实际上我想显示所有视频,就像它在照片库中打开一样(一行中的四个视频)......当我点击任何视频时......视频开始播放......

任何人都可以帮助我,这是将所有视频从文档目录显示到 ViewController 的最佳方式.... 谢谢……

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
    NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
    NSData * movieData = [NSData dataWithContentsOfURL:movieURL];
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self imageNameTextField]text]];
    fullPath = [fullPath stringByAppendingFormat:@".MOV"];
    [ movieData writeToFile:fullPath atomically:YES]; 

}

【问题讨论】:

  • 您的文档目录是否仅包含 MOV 视频或任何其他文件?
  • 那么在这种情况下,您可以获取文档目录的所有文件。你知道怎么做吗?还是我应该告诉你它的代码?
  • 是的,我知道该怎么做......
  • 我只想在视图控制器中显示它们

标签: iphone objective-c ios5 nsdocument alassetslibrary


【解决方案1】:

我建议您使用开源网格视图控件。你可以在 GitHub 中找到它们。例如,BDDynamicGridViewController 很有趣。但这不是唯一的选择。还有AQGridView

此外,还有一个流行的开源库,称为Three20,它有它的升级,称为 Nimbus。这个库有一个用于显示照片网格的自定义控件。您可以使用它来显示视频缩略图网格。例如,试试this

在您设法使用或创建网格视图控件后,您将需要视频的缩略图生成器。为此目的使用this topic

【讨论】:

    【解决方案2】:

    要访问存储在设备照片库中的视频,您需要使用资源库。以下代码向您展示了如何访问照片库中的第一个视频:

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    
    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
    
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    
    
    // Within the group enumeration block, filter to enumerate just videos.
    
    [group setAssetsFilter:[ALAssetsFilter allVideos]];
    
    
    // For this example, we're only interested in the first item.
    
    [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:0
    
           usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
    
           // The end of the enumeration is signaled by asset == nil.
    
           if (alAsset) {
    
               ALAssetRepresentation *representation = [alAsset defaultRepresentation];
    
               NSURL *url = [representation url];
    
               AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
    
               // Now you have the AV asset for the video.
    
            }
    
          }];
    
        }
    
         failureBlock: ^(NSError *error) {
    
         // Typically you should handle an error more gracefully than this.
    
         NSLog(@"No groups");
    
         }];
    
    
    [library release];
    

    这个例子在 AVFoundation 编程指南中,更多细节在Apple developer website

    【讨论】:

    • Thanx werner... 但我想从 Document 目录中获取视频
    • 好的,这意味着您需要复制或移动它们,对吗? ,这就是为什么我更喜欢直接从照片库中展示它们。你将如何展示它们?您可能需要生成缩略图才能显示它们。 AQGridView 是一个很好的库,可以在您自己的 ViewController 中显示它们。
    • 是的,我想从照片库中移动视频,当我录制任何视频时,它也存储在我的文档目录中......我不知道如何显示所有电影......所以我问这个问题
    【解决方案3】:

    我为我的一位客户做了同样的项目。我可以告诉你这个想法,但不能告诉你代码。这个想法是在拍摄或保存视频时拍摄每个视频的起始帧并将其保存为 PNG 图像作为视频的图标。通过这种方式,您将获得每个视频的图标。将所有图像保存在不同的文件夹中,以便每个图像都可以与其视频链接。现在通过以下代码从文件夹中检索所有视频

    NSFileManager *filemgr;
    filemgr = [NSFileManager defaultManager];
    filelist = [filemgr contentsOfDirectoryAtPath:path error:nil];
    

    *filelist 是 NSArray

    以同样的方式检索视频的图标。

    制作按钮的网格视图。将按钮的图像设置为视频的图标。显示视频名称。当点击视频时,打开一个新的视图控制器并制作一个视频播放器,在那里播放视频。

    【讨论】:

    猜你喜欢
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 2019-10-20
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多