2017-05-16 2 views
1

私は1つのアプリケーションを行っています。その中で私はライブ写真をキャプチャして、それをユーザーにチェックして見せたいと思っています。私は以下のコードを使ってライブ写真を撮った。私はライブの写真をキャプチャして出力URLを得ました。ライブの写真をPHLivePhotoViewに表示したいのですが、出力URLを使ってそれをどうやって行うことができますか?ライブ写真のデータも取得しています。以下のデリゲートメソッドを参照してください。ライブフォトをプレビューする方法

- (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); 
} 
+0

関連のWebViewを使用することができます:[。JPEGおよびMOVからアップルのライブ写真を作成](https://github.com/mzp/をLoveLiver) – tomfriwel

答えて

0

あなたは

PHLivePhoto.requestLivePhotoWithResourceFileURLs 

使用することができますかuがあまりに

+0

このメソッドのパラメータとして2つのURLを渡す必要があります。 –

+0

このURLを確認します。見つかりました。https://milen.me/writings/live-photo-ios-api-overview/ – vaibby

+0

これはライブ写真を保存しようとすると便利ですが、PHLivePhotoViewでライブ写真を再生するには、 2つのURLをパラメータとして渡します。 –

関連する問題