2017-05-16 2 views
1

Ich mache eine Anwendung. Darin möchte ich das Live-Foto einfangen und dem Nutzer zur Überprüfung zeigen. Ich habe das Live-Foto mit dem folgenden Code aufgenommen. Ich habe die Ausgabe-URL einmal erfassen das Live-Foto und jetzt möchte ich zeigen, dass Live-Foto in PHLivePhotoView, wie können wir das mit Ausgabe-URL tun. Und ich erhalte auch die Live-Fotodaten, siehe die Delegiertenmethoden unten.Vorschau des Livebildes

- (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

Verwandte nutzen: [. Erstellen von Apple Live-Fotos von JPEG und MOV] (https://github.com/mzp/ LoveLiver) – tomfriwel

Antwort

0

können Sie

PHLivePhoto.requestLivePhotoWithResourceFileURLs 

verwenden oder u kann webview zu

+0

brauchen zwei URLs als Parameter für diese Methode zu übergeben, wo wir sie –

+0

überprüfen können, überprüfen Sie diese URL Ich fand es https://milen.me/writings/live-photo-ios-api-overview/ – vaibby

+0

Dies ist hilfreich, wenn wir versuchen, das Live-Foto zu speichern, aber um das Live-Foto in PHLivePhotoView zu spielen, müssen wir Zwei URLs als Parameter übergeben. –