Comment puis-je get la list de tous les files video de la bibliothèque dans ios sdk

Salut, je travaille Sur les videos, je voudrais get la list des files video de la bibliothèque à l'affichage et la lecture des videos dans mon application. Quelqu'un peut-il m'aider.

allVideos = [[NSMutableArray alloc] init]; ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (group) { [group setAssetsFilter:[ALAssetsFilter allVideos]]; [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) { if (asset) { dic = [[NSMutableDictionary alloc] init]; ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation]; NSSsortingng *uti = [defaultRepresentation UTI]; NSURL *videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti]; NSSsortingng *title = [NSSsortingng ssortingngWithFormat:@"video %d", arc4random()%100]; UIImage *image = [self imageFromVideoURL:videoURL]; [dic setValue:image forKey:@"image"]; [dic setValue:title forKey:@"name"]; [dic setValue:videoURL forKey:@"url"]; [allVideos addObject:dic]; } }]; else { } } failureBlock:^(NSError *error) { NSLog(@"error enumerating AssetLibrary groups %@\n", error); }]; 

Il va ouvrir la photothèque et afficher uniquement le contenu du type de film.

 #import <MobileCoreServices/MobileCoreServices.h> UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSSsortingng *)kUTTypeMovie, nil]; [self presentModalViewController:imagePicker animated:YES]; 

Obtenir la list de toutes les videos et vignettes

Merci à @Nikhil, qui a partagé des infos ici , ça m'a aidé, mais il m'a quand même fallu quelques heures pour rendre le code exécutable car il manque quelques choses dans sa réponse

entrez la description de l'image ici

Donc, je voudrais partager mon code de travail complet

1.juste append des frameworks AssetsLibrary , AVFoundation et MediaPlayer .

2. AssetBrowserItem.h et AssetBrowserItem.m ici

3.utilisez ci-dessous le code pour get la list de toutes les videos de ios périphérique lib

4.run app et voir Log pour les détails des videos

 #import "HomeViewController.h" #import <AssetsLibrary/AssetsLibrary.h> #import <MediaPlayer/MediaPlayer.h> #import <AVFoundation/AVFoundation.h> #import "AssetBrowserItem.h" @interface HomeViewController () @property (nonatomic, strong) ALAssetsLibrary *assetsLibrary; @property (nonatomic, strong) NSURL *videoURL; @property (nonatomic, strong) MPMoviePlayerController *mpVideoPlayer; @property (nonatomic, strong) NSMutableArray *videoURLArray; @property (nonatomic, strong) NSMutableArray *assetItems; @property (nonatomic, strong) NSMutableDictionary *dic; @end @implementation HomeViewController @synthesize assetsLibrary, assetItems,dic; @synthesize videoURL,videoURLArray, mpVideoPlayer; - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Show Video List Methods - (IBAction)showVideoList:(id)sender { [self buildAssetsLibrary]; } - (void)buildAssetsLibrary { assetsLibrary = [[ALAssetsLibrary alloc] init]; ALAssetsLibrary *notificationSender = nil; videoURLArray = [[NSMutableArray alloc] init]; NSSsortingng *minimumSystemVersion = @"4.1"; NSSsortingng *systemVersion = [[UIDevice currentDevice] systemVersion]; if ([systemVersion compare:minimumSystemVersion options:NSNumericSearch] != NSOrderedAscending) notificationSender = assetsLibrary; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(assetsLibraryDidChange:) name:ALAssetsLibraryChangedNotification object:notificationSender]; [self updateAssetsLibrary]; } - (void)assetsLibraryDidChange:(NSNotification*)changeNotification { [self updateAssetsLibrary]; } - (void)updateAssetsLibrary { assetItems = [NSMutableArray arrayWithCapacity:0]; ALAssetsLibrary *assetLibrary = assetsLibrary; [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (group) { [group setAssetsFilter:[ALAssetsFilter allVideos]]; [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) { if (asset) { dic = [[NSMutableDictionary alloc] init]; ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation]; NSSsortingng *uti = [defaultRepresentation UTI]; videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti]; mpVideoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; NSSsortingng *title = [NSSsortingng ssortingngWithFormat:@"%@ %lu", NSLocalizedSsortingng(@"Video", nil), [assetItems count]+1]; [self performSelector:@selector(imageFromVideoURL)]; [dic setValue:title forKey:@"VideoTitle"];//kName [dic setValue:videoURL forKey:@"VideoUrl"];//kURL AssetBrowserItem *item = [[AssetBrowserItem alloc] initWithURL:videoURL title:title]; [assetItems addObject:item]; [videoURLArray addObject:dic]; NSLog(@"Video has info:%@",videoURLArray); } NSLog(@"Values of dictonary==>%@", dic); //NSLog(@"assetItems:%@",assetItems); NSLog(@"Videos Are:%@",videoURLArray); } ]; } // group == nil signals we are done iterating. else { dispatch_async(dispatch_get_main_queue(), ^{ //[self updateBrowserItemsAndSignalDelegate:assetItems]; // loadImgView.hidden = NO; // [spinner stopAnimating]; // [loadImgView removeFromSuperview]; //selectVideoBtn .userInteractionEnabled = YES; }); } } failureBlock:^(NSError *error) { NSLog(@"error enumerating AssetLibrary groups %@\n", error); }]; } - (UIImage *)imageFromVideoURL { UIImage *image = nil; AVAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];; AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; imageGenerator.appliesPreferredTrackTransform = YES; // calc midpoint time of video Float64 durationSeconds = CMTimeGetSeconds([asset duration]); CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600); // get the image from NSError *error = nil; CMTime actualTime; CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error]; if (halfWayImage != NULL) { // cgimage to uiimage image = [[UIImage alloc] initWithCGImage:halfWayImage]; [dic setValue:image forKey:@"ImageThumbnail"];//kImage NSLog(@"Values of dictonary==>%@", dic); NSLog(@"Videos Are:%@",videoURLArray); CGImageRelease(halfWayImage); } return image; } @end 

utilisez cette méthode pour choisir des videos de la bibliothèque.

  //Call this method. [self startMediaBrowserFromViewController: self usingDelegate: self]; - (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate{ if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO) || (delegate == nil) || (controller == nil)) return NO; UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init]; mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; mediaUI.mediaTypes = [[[NSArray alloc] initWithObjects: (NSSsortingng *) kUTTypeMovie, nil] autorelease]; mediaUI.allowsEditing = YES; mediaUI.delegate = self; mediaUI.videoMaximumDuration = 60.0; //mediaUI.videoQuality = UIImagePickerControllerQualityTypeLow; [controller presentModalViewController: mediaUI animated: YES]; return YES; } 

Veuillez vous référer au lien ci-dessous. Cela peut vous être utile

http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios
Bonne chance !!!

Consultez l'article de blog pour récupérer tous les éléments video en utilisant 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 

}