美文网首页
iOS 将视频保存为livephoto图片,设置为手机动态封面图

iOS 将视频保存为livephoto图片,设置为手机动态封面图

作者: 流云_henry | 来源:发表于2019-12-20 15:04 被阅读0次
    /**
     将视频转为livephoto保存到本地
    
     @param videoPath 视频地址
     @param imagePath 图片地址
     @param saveHandle 返回回调
     */
    - (void)saveLivePhotoWithVideoPath:(NSString *)videoPath
                             imagePath:(NSString *)imagePath
                                handle:(void(^)(BOOL,NSError *))saveHandle;
    
    - (void)saveLivePhotoWithVideoPath:(NSString *)videoPath imagePath:(NSString *)imagePath handle:(void(^)(BOOL,NSError *))saveHandle{
        [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
            PHAssetCreationRequest *creationRequest = [PHAssetCreationRequest creationRequestForAsset];
            PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
            
            [creationRequest addResourceWithType:PHAssetResourceTypePairedVideo fileURL:[NSURL fileURLWithPath:videoPath] options:options];
            [creationRequest addResourceWithType:PHAssetResourceTypePhoto fileURL:[NSURL fileURLWithPath:imagePath] options:options];
            
        } completionHandler:^(BOOL success, NSError * _Nullable error) {
            saveHandle(success,error);
        }];
    }
    

    相关文章

      网友评论

          本文标题:iOS 将视频保存为livephoto图片,设置为手机动态封面图

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