Advertisement
Guest User

Untitled

a guest
Feb 14th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (PHLivePhoto *)convertLivePhotoFromVideoURL:(NSURL *)videoURL photoURL:(NSURL *)photoURL {
  2.     CGSize targetSize = CGSizeZero;
  3.     PHImageContentMode contentMode = PHImageContentModeDefault;
  4.    
  5.     // call scary Private API to create the live photo
  6.     PHLivePhoto *livePhoto = [[PHLivePhoto alloc] init];
  7.     SEL initWithImageURLvideoURL = NSSelectorFromString(@"_initWithImageURL:videoURL:targetSize:contentMode:");
  8.    
  9.     if ([livePhoto respondsToSelector:initWithImageURLvideoURL]) {
  10.         if(invocation == nil)
  11.             invocation = [NSInvocation invocationWithMethodSignature:[livePhoto methodSignatureForSelector:initWithImageURLvideoURL]];
  12.         [invocation setSelector:initWithImageURLvideoURL];
  13.         [invocation setTarget:livePhoto];
  14.         [invocation setArgument:&(photoURL) atIndex:2];
  15.         [invocation setArgument:&(videoURL) atIndex:3];
  16.         [invocation setArgument:&(targetSize) atIndex:4];
  17.         [invocation setArgument:&(contentMode) atIndex:5];
  18.         [invocation invoke];
  19.     }
  20.    
  21.     //    // save it to the camera roll
  22.     //    [self saveLivePhotoAssetWithVideoURL:videoURL imageURL:photoURL];
  23.    
  24.     //    NSArray *resources = @[videoURL, photoURL];
  25.     //
  26.     //    [PHLivePhoto requestLivePhotoWithResourceFileURLs:resources placeholderImage:nil targetSize:CGSizeZero contentMode:PHImageContentModeAspectFit resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nonnull info) {
  27.     //
  28.     //        // completion handler
  29.     //        NSLog(@"Completion handler has been called.");
  30.     //        self.livePhoto = livePhoto;
  31.     //    }];
  32.    
  33.     return livePhoto;
  34. }
  35.  
  36. -(void) setLivePhoto {
  37.     if(_livePhotoView.livePhoto !=nil) return;
  38.     NSString *path = [ERFileManager getMainPathForAlbumName:_albumName imageName:_imageName];
  39.     NSString *imgName = [_imageName stringByReplacingOccurrencesOfString:@".mp4" withString:@".jpg"];
  40.     NSString *imagePath = [ERFileManager getMainPathForAlbumName:_albumName imageName:imgName];
  41.    
  42.     NSURL *videoUrl = [NSURL fileURLWithPath:path];
  43.     UIImage *image = [UIImage imageWithContentsOfFile:imagePath];//[self firstFrame:videoUrl];
  44.     NSURL *photoURL = [NSURL fileURLWithPath:imagePath];//[self grabFileURL:@"tempPhoto.jpg"];
  45.     //NSData *data = UIImagePNGRepresentation(image);
  46.     //[data writeToURL:photoURL atomically:YES];
  47.     NSArray *resources = @[videoUrl, photoURL];
  48.    
  49.     [PHLivePhoto requestLivePhotoWithResourceFileURLs:resources placeholderImage:image targetSize:CGSizeZero contentMode:PHImageContentModeAspectFit resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nonnull info) {
  50.         [_livePhotoView setLivePhoto:livePhoto];
  51.         //[_livePhotoView startPlaybackWithStyle:PHLivePhotoViewPlaybackStyleHint];
  52.         _livePhotoView.contentMode = UIViewContentModeScaleAspectFit;
  53.     }];
  54.     _livePhotoBadge.image = [PHLivePhotoView livePhotoBadgeImageWithOptions:PHLivePhotoBadgeOptionsOverContent];
  55. //    PHLivePhoto *livePhoto = [self convertLivePhotoFromVideoURL:videoUrl photoURL:photoURL];
  56. //    _livePhotoView.livePhoto = livePhoto;
  57. //    _livePhotoView.contentMode = UIViewContentModeScaleAspectFit;
  58. //    livePhoto = nil;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement