How Can i Get the List of all Video files from Library in ios sdk

前端 未结 7 2457
[愿得一人]
[愿得一人] 2020-12-09 06:13

Hi I\'m working On videos , i would like get the list of video files from library to Display and playing the Videos in my app. can any one help me.

7条回答
  •  猫巷女王i
    2020-12-09 07:04

    Checkout the blog post to fetch all video assets using Photos Framework http://iavinashkashyap.blogspot.in/2016/11/get-list-of-all-videos.html

    Code:

    -(void) getAllVideoAssets{

    NSMutableArray *assets = [[NSMutableArray alloc] init];
    //Fetch all video assets from Photos
    PHFetchResult *assetResults = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil];
    //get all assets
    for (PHAsset *asset in assetResults){
        NSLog(@"asset type = %zd", asset.mediaType);
        [assets addObject:asset];
    }
    self.allVideoslistArray = [[NSMutableArray alloc] init];
    //create an instance of PHImageManager
    PHImageManager *manager = [PHImageManager defaultManager];
    for(PHAsset *asset in assets){
        //block of code for represent video assets
        [manager requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
            if ([asset isKindOfClass:[AVURLAsset class]]) {
                NSURL *url = (NSURL *)[[(AVURLAsset *)asset URL] fileReferenceURL];
                UIImage *thumbnail = [self createThunbnailImage:url];
                [self.allVideoslistArray addObject:@{@"VideoUrl":url,@"ThumbnailImage":thumbnail, @"VideoAsset":asset}];
            }
        }];
    }//end for loop
    

    }

提交回复
热议问题