Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (PHLivePhoto *)convertLivePhotoFromVideoURL:(NSURL *)videoURL photoURL:(NSURL *)photoURL {
- CGSize targetSize = CGSizeZero;
- PHImageContentMode contentMode = PHImageContentModeDefault;
- // call scary Private API to create the live photo
- PHLivePhoto *livePhoto = [[PHLivePhoto alloc] init];
- SEL initWithImageURLvideoURL = NSSelectorFromString(@"_initWithImageURL:videoURL:targetSize:contentMode:");
- if ([livePhoto respondsToSelector:initWithImageURLvideoURL]) {
- if(invocation == nil)
- invocation = [NSInvocation invocationWithMethodSignature:[livePhoto methodSignatureForSelector:initWithImageURLvideoURL]];
- [invocation setSelector:initWithImageURLvideoURL];
- [invocation setTarget:livePhoto];
- [invocation setArgument:&(photoURL) atIndex:2];
- [invocation setArgument:&(videoURL) atIndex:3];
- [invocation setArgument:&(targetSize) atIndex:4];
- [invocation setArgument:&(contentMode) atIndex:5];
- [invocation invoke];
- }
- // // save it to the camera roll
- // [self saveLivePhotoAssetWithVideoURL:videoURL imageURL:photoURL];
- // NSArray *resources = @[videoURL, photoURL];
- //
- // [PHLivePhoto requestLivePhotoWithResourceFileURLs:resources placeholderImage:nil targetSize:CGSizeZero contentMode:PHImageContentModeAspectFit resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nonnull info) {
- //
- // // completion handler
- // NSLog(@"Completion handler has been called.");
- // self.livePhoto = livePhoto;
- // }];
- return livePhoto;
- }
- -(void) setLivePhoto {
- if(_livePhotoView.livePhoto !=nil) return;
- NSString *path = [ERFileManager getMainPathForAlbumName:_albumName imageName:_imageName];
- NSString *imgName = [_imageName stringByReplacingOccurrencesOfString:@".mp4" withString:@".jpg"];
- NSString *imagePath = [ERFileManager getMainPathForAlbumName:_albumName imageName:imgName];
- NSURL *videoUrl = [NSURL fileURLWithPath:path];
- UIImage *image = [UIImage imageWithContentsOfFile:imagePath];//[self firstFrame:videoUrl];
- NSURL *photoURL = [NSURL fileURLWithPath:imagePath];//[self grabFileURL:@"tempPhoto.jpg"];
- //NSData *data = UIImagePNGRepresentation(image);
- //[data writeToURL:photoURL atomically:YES];
- NSArray *resources = @[videoUrl, photoURL];
- [PHLivePhoto requestLivePhotoWithResourceFileURLs:resources placeholderImage:image targetSize:CGSizeZero contentMode:PHImageContentModeAspectFit resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nonnull info) {
- [_livePhotoView setLivePhoto:livePhoto];
- //[_livePhotoView startPlaybackWithStyle:PHLivePhotoViewPlaybackStyleHint];
- _livePhotoView.contentMode = UIViewContentModeScaleAspectFit;
- }];
- _livePhotoBadge.image = [PHLivePhotoView livePhotoBadgeImageWithOptions:PHLivePhotoBadgeOptionsOverContent];
- // PHLivePhoto *livePhoto = [self convertLivePhotoFromVideoURL:videoUrl photoURL:photoURL];
- // _livePhotoView.livePhoto = livePhoto;
- // _livePhotoView.contentMode = UIViewContentModeScaleAspectFit;
- // livePhoto = nil;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement