display all videos stored in document directory

☆樱花仙子☆ 提交于 2019-12-06 16:35:36
wzbozon

I recommend you to use an open-source grid-view control. You can find them in GitHub. For instance, BDDynamicGridViewController is interesting. But it is not the only option. There is also AQGridView.

Also, there is a popular open-source library, called Three20 and it has it's upgrade, called Nimbus. This library has a custom control for displaying photos grid. You can use the same for displaying video thumbnails grid. For instance, try this.

After you will manage to use or create Grid view control, you will need thumbnail generator for the videos. Use this topic for that purpose.

To get access to the videos stored in the photo library on the device you need to use the Asset library. The following code shows you how to get access to the first video in the photo library :

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

This example is in the AVFoundation Programming guide, more details on the Apple developer website

I have made the same project for one of my client. I can tell you the idea but cann't tell you the code. The idea is while taking or saving video take the starting frame of every video and save it as PNG image as icon of the video. By this way you will get the icon of every video. Save all the Images in different folder in such a manner that each image can be link with its video. Now retrieve all videos from the document folder by below code

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

*filelist is the NSArray

In the same manner retrieve the icons of the videos.

Make a grid view of buttons. Set images of the buttons as icons of the videos. Show the video names. When click on the video open a new view controller and make a video player ther play the video there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!