0

I found that VLC.app save video to album quickly. But my code will cost long time. Or it crash. How can I optimazed it. (compare with same large video)

Here is my code.

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    assetId = [PHAssetCreationRequest creationRequestForAssetFromVideoAtFileURL:fileUrl].placeholderForCreatedAsset.localIdentifier;
} completionHandler:^(BOOL success, NSError * _Nullable error) {
    if (!success) {
        if(onError)onError(error);
        return ;
    }
    PHAssetCollection *collection = [self getAlbumCollection:collectionStr];
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetCollectionChangeRequest *request = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection];
        PHAsset *asset = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil].firstObject;
        [request addAssets:@[asset]];
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        if (!success) {
            if(onError)onError(error);
            return;
        }
        if(onComplete)onComplete(fileUrl);
    }];
}];
matt
  • 515,959
  • 87
  • 875
  • 1,141
zszen
  • 1,428
  • 1
  • 14
  • 18
  • 1
    I don't see how you know that VLC is faster. Maybe it just _looks_ faster because it doesn't wait for the completion handler before updating the interface. Meanwhile the saving continues in the background. – matt Aug 03 '18 at 17:27
  • My illustion. It is fast real from app cache to album. But hard from album copy to app. – zszen Aug 03 '18 at 18:14

0 Answers0