Skip to content

Commit

Permalink
Merge pull request Yummypets#163 from Yummypets/liveVideoOrientation
Browse files Browse the repository at this point in the history
Taking live videos - Now takes into account orientation
  • Loading branch information
s4cha authored Jun 25, 2018
2 parents be65cde + 6329418 commit acc3db4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Source/Pages/Video/YPVideoHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ class YPVideoHelper: NSObject {
return
}
}

let connection = videoOutput.connection(with: .video)
if (connection?.isVideoOrientationSupported)! {
connection?.videoOrientation = currentVideoOrientation()
}

videoOutput.startRecording(to: outputURL, recordingDelegate: self)
}

Expand Down Expand Up @@ -198,6 +204,23 @@ class YPVideoHelper: NSObject {
}
}

// MARK: - Orientation

func currentVideoOrientation() -> AVCaptureVideoOrientation {
var orientation: AVCaptureVideoOrientation
switch UIDevice.current.orientation {
case .portrait:
orientation = .portrait
case .landscapeRight:
orientation = .landscapeLeft
case .portraitUpsideDown:
orientation = .portraitUpsideDown
default:
orientation = .landscapeRight
}
return orientation
}

// MARK: - Preview

func tryToSetupPreview() {
Expand All @@ -215,7 +238,6 @@ class YPVideoHelper: NSObject {
self.previewView.layer.addSublayer(videoLayer)
}
}

}

extension YPVideoHelper: AVCaptureFileOutputRecordingDelegate {
Expand Down

0 comments on commit acc3db4

Please sign in to comment.