美文网首页
获取系统视频数据

获取系统视频数据

作者: 寻找最亮的光 | 来源:发表于2020-11-26 20:46 被阅读0次

import <Photos/Photos.h>

  • (void)getVideoData {
    PHFetchResult<PHAssetCollection *> *sysVideos = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumVideos options:nil];

    for (PHAssetCollection *collection in sysVideos) {
    MTFolderInfoModel *model = [[MTFolderInfoModel alloc] init];
    model.isVideo = YES;
    model.collection = collection;

     if (model.collectionNumber == 0) {
         break;
     }
     NSLog(@"videoCount-----%ld----",model.collectionNumber);
     for (NSInteger j = 0; j < model.fillArr.count; j++) {
         MTFolderFileInfoModel *fileModel = model.fillArr[j];
         PHAsset *asset = fileModel.asset;
         //直接获取视频信息
         PHImageManager *imageManager = [PHImageManager defaultManager];
         PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
         options.version = PHImageRequestOptionsVersionCurrent;
         options.networkAccessAllowed = YES;
         options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
         [imageManager requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
             if ([asset isKindOfClass:[AVURLAsset class]]) {
                 AVURLAsset* urlAsset = (AVURLAsset*)asset;
                 NSNumber *size;
                 [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
                 
                 //和运行内存有关?超过1G获取不到
                 NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL?urlAsset.URL:[NSURL URLWithString:@""] options:NSDataReadingMappedIfSafe error:nil];
                 //---尝试获取数据---
    

// NSData *videoDd = [NSData dataWithContentsOfFile:urlAsset.URL.absoluteString];
NSLog(@"path-22---%@----size----%ld----length----%ld----",urlAsset.URL.absoluteString,(long)size.integerValue,videoData.length);
//---尝试获取数据---

               if (videoData.length == 0) {
                   NSNumber *size;
                   [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
                   
               }

// NSFileManager* fileManager = [NSFileManager defaultManager];
//
// if ([fileManager fileExistsAtPath:@"private/var/mobile/Media/DCIM/105APPLE/IMG_5924.MOV"]) {
// NSLog(@"文件存在读取文件~");
// NSData* readData = [fileManager contentsAtPath:@"/private/var/mobile/Media/DCIM/105APPLE/IMG_5924.MOV"];
// NSLog(@"path-CC---%@----size----%ld----length----%ld----",urlAsset.URL.absoluteString,(long)size.integerValue,readData.length);
// }
}
}];
}
}
}

相关文章

网友评论

      本文标题:获取系统视频数据

      本文链接:https://www.haomeiwen.com/subject/qxiziktx.html