簡體   English   中英

如何預覽livephoto

[英]How to preview the livephoto

我正在做一個申請。 在那里我想拍攝實時照片並將其顯示給用戶進行檢查。 我使用下面的代碼拍攝了實時照片。 我得到了輸出網址,一旦捕獲了實時照片,現在我想在PHLivePhotoView顯示實時照片,我們如何使用輸出網址來做到這一點。 我也獲得了實時照片數據,請參閱下面的委托方法。

- (void)viewDidLoad {
    [super viewDidLoad];
    //Capture Session
    AVCaptureSession *session = [[AVCaptureSession alloc]init];
    session.sessionPreset = AVCaptureSessionPresetPhoto;

    //Add device
    AVCaptureDevice *device =
    [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    //Input
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];

    if (!input)
    {
        NSLog(@"No Input");
    }

    [session addInput:input];

    //Output
     //    AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
     //    [session addOutput:output];
    //    output.videoSettings =
    //    @{ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };

    AVCapturePhotoOutput *output =[[AVCapturePhotoOutput alloc]init];
    [session addOutput:output];
    output.livePhotoCaptureEnabled = true;
    output.highResolutionCaptureEnabled = YES;
    //Preview Layer
    previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    UIView *myView = self.previewView;
    previewLayer.frame = myView.bounds;
    previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [self.previewView.layer addSublayer:previewLayer];

    //Start capture session
    [session startRunning];
    [session commitConfiguration];
    captureOutput = [[AVCapturePhotoOutput alloc]init];
    captureOutput = output;

    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)captureImage:(id)sender
{
    AVCapturePhotoSettings * settings = [AVCapturePhotoSettings photoSettings];
    settings.highResolutionPhotoEnabled = YES;
    settings.flashMode = AVCaptureFlashModeOn;
    NSString *livePhotoMovieFileName = [NSUUID UUID].UUIDString;
    NSString *livePhotoMovieFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[livePhotoMovieFileName stringByAppendingPathExtension:@"mov"]];
    settings.livePhotoMovieFileURL = [NSURL fileURLWithPath:livePhotoMovieFilePath];
    [captureOutput capturePhotoWithSettings:settings delegate:self];
}

- (void)captureOutput:(AVCapturePhotoOutput *)captureOutput didFinishProcessingLivePhotoToMovieFileAtURL:(NSURL *)outputFileURL duration:(CMTime)duration photoDisplayTime:(CMTime)photoDisplayTime resolvedSettings:(AVCaptureResolvedPhotoSettings *)resolvedSettings error:(nullable NSError *)error
   {
      NSLog(@"%@",outputFileURL);
   }

- (void)captureOutput:(AVCapturePhotoOutput *)captureOutput didFinishProcessingPhotoSampleBuffer:(nullable CMSampleBufferRef)photoSampleBuffer previewPhotoSampleBuffer:(nullable CMSampleBufferRef)previewPhotoSampleBuffer resolvedSettings:(AVCaptureResolvedPhotoSettings *)resolvedSettings bracketSettings:(nullable AVCaptureBracketedStillImageSettings *)bracketSettings error:(nullable NSError *)error
{
    photoData = [AVCapturePhotoOutput JPEGPhotoDataRepresentationForJPEGSampleBuffer:photoSampleBuffer previewPhotoSampleBuffer:previewPhotoSampleBuffer];
    NSLog(@"%@",photoData);
}

您可以使用

PHLivePhoto.requestLivePhotoWithResourceFileURLs

或者你也可以使用webview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM