36 Commits

Author SHA1 Message Date
Ahmed Bekhit 350a67d63e Update Pod versions 2020-01-10 13:36:32 -05:00
Ahmed Bekhit 0832eeb927 Update + validate podspec 2020-01-10 12:59:27 -05:00
Ahmed Bekhit 3eb3c4db2b Update podspec file 2020-01-10 12:40:15 -05:00
Ahmed Bekhit f2f64a6580 Merge pull request #94 from wolfcon/fix/xcode-11-error-for-PHLivePhotoPlus
Fix PHLivePhoto in Xcode 11 (iOS 13 SDK) error : `'init()' has been xplicitly marked unavailable here (Photos.PHLivePhoto)`
2019-08-21 08:26:16 -04:00
Frank e388eaa21e Fix PHLivePhoto in Xcode 11 (iOS 13 SDK) error : 'init()' has been explicitly marked unavailable here (Photos.PHLivePhoto) 2019-08-21 17:48:36 +08:00
Ahmed Bekhit 507ec687c3 Change didCancel protocol to optional 2019-06-25 22:21:49 -04:00
Ahmed Bekhit d79e2d4829 Merge pull request #72 from asam139/feature/cancel_recording
Cancel recording
2019-06-25 22:14:54 -04:00
Ahmed Bekhit 387c864e71 Merge branch 'swift_4_2' into feature/cancel_recording 2019-06-25 22:14:29 -04:00
Ahmed Bekhit c44194230b Update README.md 2019-06-25 22:08:09 -04:00
Ahmed Bekhit 7870134192 Update README.md 2019-06-25 22:07:56 -04:00
Ahmed Bekhit 3cb80cba01 Update README.md 2019-05-13 09:13:59 -04:00
Ahmed Bekhit 658fb4ca07 Update README.md 2019-05-13 09:13:41 -04:00
Ahmed Bekhit 94e3dddfea Merge @asam139 contribution
Fix memory issues and enhance performance
2019-05-04 11:50:00 -04:00
Saul Moreno Abril d3f52c26f4 Fix crash: it checks resumeFrameTime is not nil 2019-05-03 16:10:49 +01:00
Saul Moreno Abril 4dd890a885 Fix memory leak using leak for delegate's WritAR 2019-05-01 15:49:53 +01:00
Saul Moreno Abril a320a51e90 Use weak proxy for CADisplayLink to broke the leak memory 2019-05-01 15:31:52 +01:00
Saul Moreno Abril 1ab12173f4 Move var as private and not global 2019-05-01 15:31:46 +01:00
Saul Moreno Abril a513e4157f Fix leak memory parent view must be weak reference 2019-05-01 15:07:05 +01:00
Ahmed Bekhit 11b1d4738b Update README.md 2019-03-06 10:38:01 -05:00
AFathi 7a63dbe34a minor bug fixes 2019-03-01 17:22:19 -05:00
Ahmed Bekhit 05ee09b1ce Merge pull request #73 from asam139/feature/current_duration
Add delegate to get progress of duration of current recording
2019-03-01 16:52:44 -05:00
Ahmed Bekhit 30afffd79f Merge pull request #77 from Svrf/fix-bug-when-crash
Fix bug when app crashes after stop video recording
2019-03-01 16:50:21 -05:00
Andrey Evstratenko 3b6e4f60c8 fix bug when app crashes 2019-02-27 15:58:59 +03:00
Saul Moreno Abril 7b5326adcb Add delegate to get progress of duration of current recording 2019-01-15 19:09:26 +01:00
Saul Moreno Abril e6d24ec1b4 Fix grammar 2019-01-15 19:02:59 +01:00
Saul Moreno Abril 5c419c3031 Add method to cancel recording (deleting current url) 2019-01-10 20:51:51 +01:00
Ahmed Bekhit 0653f11cfd Merge pull request #71 from asam139/fix/deprecated_swift_version_file
Deprecated swift_version file
2019-01-06 21:28:38 -05:00
Saul Moreno Abril bc70751aff Remove the ".swift-version" file which is now deprecated and only use the "swift_version" attribute within your podspec. 2019-01-05 19:52:56 +01:00
Ahmed Bekhit ebb2d0a485 Merge pull request #70 from youllbejustfine/swift_4_2
Bypassing pixel buffer attributes - Resolving recording issues that occurred on iPhone X and higher devices
2018-12-17 11:54:41 -05:00
Lukas Steinman 483bf4563b Bypassing pixel buffer attributes to resolve recordings not working on iPhone X/XS/XMax devices. 2018-12-17 12:21:48 -04:00
Ahmed Bekhit 2015b4db0e Update README.md 2018-09-26 23:08:47 -04:00
AFathi 85e846ef25 swift4.2 fixes xcode10 GM 2018-09-25 16:51:07 -04:00
AFathi 8420a3808f fixes for final xcode10 version 2018-09-25 16:26:11 -04:00
AFathi 1fb3a03593 Swift project update to 4.2 2018-09-20 12:08:58 -04:00
AFathi cd0d7f34cf Swift 4.2 Support 2018-09-20 12:02:07 -04:00
AFathi 6a4290e17b swift 4.2 branch 2018-09-20 11:45:09 -04:00
18 changed files with 181 additions and 93 deletions
-1
View File
@@ -1 +0,0 @@
echo "4.0" > .swift-version
+4 -3
View File
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "ARVideoKit"
s.version = "1.3"
s.version = "1.51"
s.summary = "Capture & record ARKit videos 📹, photos 🌄, Live Photos 🎇, and GIFs 🎆."
s.description = "Enabling developers to capture videos 📹, photos 🌄, Live Photos 🎇, and GIFs 🎆 with augmented reality components."
s.homepage = "https://github.com/AFathi/ARVideoKit"
s.screenshots = "http://www.ahmedbekhit.com/SK_PREV.gif", "http://www.ahmedbekhit.com/SCN_PREVIEW.gif"
s.swift_version = '4.2'
s.license = { :type => "Apache 2.0", :file => "LICENSE" }
@@ -16,7 +16,8 @@ Pod::Spec.new do |s|
s.platform = :ios, "11.0"
s.source = { :git => "https://github.com/AFathi/ARVideoKit.git", :tag => "1.3" }
# ARVideoKit for Swift 4.2
s.source = { :git => "https://github.com/AFathi/ARVideoKit.git", :tag => "1.51" }
s.source_files = "ARVideoKit", "ARVideoKit/**/*.{h,m,swift}"
s.resources = "ARVideoKit/Assets/*.scnassets"
end
+14 -2
View File
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
B466A8B82279E34C00BD7070 /* WeakProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = B466A8B72279E34C00BD7070 /* WeakProxy.swift */; };
FB2E36891FAE29C00035B8D6 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = FB2E36881FAE29BF0035B8D6 /* LICENSE */; };
FB404FFE20D72A190056EA1D /* JPEG.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB404FFD20D72A190056EA1D /* JPEG.swift */; };
FBD604DF1FA969DD00EC9804 /* ARVideoKit.h in Headers */ = {isa = PBXBuildFile; fileRef = FBD604DD1FA969DD00EC9804 /* ARVideoKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -33,6 +34,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
B466A8B72279E34C00BD7070 /* WeakProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakProxy.swift; sourceTree = "<group>"; };
FB2E36881FAE29BF0035B8D6 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
FB404FFD20D72A190056EA1D /* JPEG.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JPEG.swift; sourceTree = "<group>"; };
FBD604DA1FA969DD00EC9804 /* ARVideoKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ARVideoKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -71,6 +73,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
B466A8B62279E33800BD7070 /* Utils */ = {
isa = PBXGroup;
children = (
B466A8B72279E34C00BD7070 /* WeakProxy.swift */,
);
path = Utils;
sourceTree = "<group>";
};
FBA0AA0A1FAD9D9D006C481B /* Writer */ = {
isa = PBXGroup;
children = (
@@ -99,6 +109,7 @@
FBD604DC1FA969DD00EC9804 /* ARVideoKit */ = {
isa = PBXGroup;
children = (
B466A8B62279E33800BD7070 /* Utils */,
FBD604E51FA96ACD00EC9804 /* Assets */,
FBD604E61FA96AD400EC9804 /* Enumerations */,
FBD604E71FA96AE500EC9804 /* Extensions */,
@@ -290,6 +301,7 @@
FBD604F51FA96B3300EC9804 /* UIImage+VideoBuffer.swift in Sources */,
FBD605111FA96BA100EC9804 /* ARView.swift in Sources */,
FBD604F61FA96B3300EC9804 /* CGImage+Resize.swift in Sources */,
B466A8B82279E34C00BD7070 /* WeakProxy.swift in Sources */,
FBD604F91FA96B3300EC9804 /* UIViewController+hasType.swift in Sources */,
FBD605141FA96BA100EC9804 /* ViewAR.swift in Sources */,
FBD604EE1FA96B2700EC9804 /* ARVideoOptions.swift in Sources */,
@@ -450,7 +462,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@@ -475,7 +487,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.ahmedbekhit.ARVideoKit;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
+1 -1
View File
@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.31</string>
<string>1.32</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
@@ -28,12 +28,25 @@ import ARKit
- parameter noError: A boolean that returns true when the recorder ends without errors. Otherwise, it returns false.
*/
func recorder(didEndRecording path: URL, with noError: Bool)
/**
A protocol method that is triggered when a recorder fails recording.
- parameter error: An `Error` object that returns the error value.
- parameter status: A string that returns the reason of the recorder failure in a string literal format.
*/
func recorder(didFailRecording error: Error?, and status: String)
/**
A protocol method that is triggered when a recorder is cancelled.
- parameter status: A string that returns the reason the of recorder cancelation in a string literal format.
*/
@objc optional func recorder(didCancelRecording status: String)
/**
A protocol method that is triggered when a recorder is modified.
- parameter duration: A double that returns the duration of current recording
*/
@objc optional func recorder(didUpdateRecording duration: TimeInterval)
/**
A protocol method that is triggered when the application will resign active.
@@ -26,11 +26,11 @@ class LivePhotoGenerator {
generator.appliesPreferredTrackTransform = true
//retrieves the key photo frame from the middle of the video asset
let time = NSValue(time: CMTimeMultiplyByFloat64(asset.duration, 0.5))
let time = NSValue(time: CMTimeMultiplyByFloat64(asset.duration, multiplier: 0.5))
//generates the key photo CGImage asynchronously
generator.generateCGImagesAsynchronously(forTimes: [time], completionHandler: { _, image, _, _, _ in
if let cgImg = image, let imgData = UIImagePNGRepresentation(UIImage(cgImage: cgImg)) {
if let cgImg = image, let imgData = UIImage(cgImage: cgImg).pngData() {
do {
self.keyPhotoPath = self.newPath(for: true, and: false)
try imgData.write(to: self.keyPhotoPath!, options: [.atomic])
@@ -16,7 +16,7 @@ class QuickTimeMov {
private let kKeyStillImageTime = "com.apple.quicktime.still-image-time"
private let kKeySpaceQuickTimeMetadata = "mdta"
private let path: String
private let dummyTimeRange = CMTimeRangeMake(CMTimeMake(0, 1000), CMTimeMake(200, 3000))
private let dummyTimeRange = CMTimeRange(start: CMTime(value: 0, timescale: 1000), duration: CMTime(value: 200, timescale: 3000))
private lazy var asset: AVURLAsset = {
let url = URL(fileURLWithPath: self.path)
@@ -128,7 +128,7 @@ class QuickTimeMov {
// --------------------------------------------------
writer.startWriting()
reader.startReading()
writer.startSession(atSourceTime: kCMTimeZero)
writer.startSession(atSourceTime: CMTime.zero)
// write metadata track
adapter.append(AVTimedMetadataGroup(items: [metadataForStillImageTime()],
@@ -148,7 +148,7 @@ class QuickTimeMov {
input.markAsFinished()
if reader.status == .completed && aAudioAsset.tracks.count > 1 {
audioReader?.startReading()
writer.startSession(atSourceTime: kCMTimeZero)
writer.startSession(atSourceTime: CMTime.zero)
let media_queue = DispatchQueue(label: "assetAudioWriterQueue", attributes: [])
audioWriterInput?.requestMediaDataWhenReady(on: media_queue) {
while (audioWriterInput?.isReadyForMoreMediaData)! {
@@ -218,7 +218,9 @@ class QuickTimeMov {
"com.apple.metadata.datatype.int8" ]
var desc: CMFormatDescription? = nil
CMMetadataFormatDescriptionCreateWithMetadataSpecifications(kCFAllocatorDefault, kCMMetadataFormatType_Boxed, [spec] as CFArray, &desc)
CMMetadataFormatDescriptionCreateWithMetadataSpecifications(allocator: kCFAllocatorDefault, metadataType: kCMMetadataFormatType_Boxed, metadataSpecifications: [spec] as CFArray, formatDescriptionOut: &desc)
// CMFormatDescription.createForMetadata(allocator: kCFAllocatorDefault, metadataType: kCMMetadataFormatType_Boxed, metadataSpecifications: [spec] as CFArray, formatDescriptionOut: &desc)
let input = AVAssetWriterInput(mediaType: AVMediaType.metadata,
outputSettings: nil, sourceFormatHint: desc)
return AVAssetWriterInputMetadataAdaptor(assetWriterInput: input)
@@ -18,7 +18,7 @@ import Photos
* [Email](mailto:me@ahmedbekhit.com)
*/
@available(iOS 9.1, *)
@objc public class PHLivePhotoPlus: PHLivePhoto {
@objc public class PHLivePhotoPlus: NSObject {
var pairedVideoPath: URL?
var keyPhotoPath: URL?
+2 -3
View File
@@ -9,11 +9,10 @@
import Foundation
import ARKit
private var view: Any?
private var renderEngine: SCNRenderer!
@available(iOS 11.0, *)
struct RenderAR {
private var view: Any?
private var renderEngine: SCNRenderer!
var ARcontentMode: ARFrameMode!
init(_ ARview: Any?, renderer: SCNRenderer, contentMode: ARFrameMode) {
+26 -32
View File
@@ -25,7 +25,7 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
private var isRecording: Bool = false
var delegate: RecordARDelegate?
weak var delegate: RecordARDelegate?
var videoInputOrientation: ARVideoOrientation = .auto
init(output: URL, width: Int, height: Int, adjustForSharing: Bool, audioEnabled: Bool, orientaions:[ARInputViewOrientation], queue: DispatchQueue, allowMix: Bool) {
@@ -38,8 +38,8 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
}
if audioEnabled {
if allowMix {
let audioOptions: AVAudioSessionCategoryOptions = [.mixWithOthers , .allowBluetooth, .defaultToSpeaker, .interruptSpokenAudioAndMixWithOthers]
try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: audioOptions)
let audioOptions: AVAudioSession.CategoryOptions = [.mixWithOthers , .allowBluetooth, .defaultToSpeaker, .interruptSpokenAudioAndMixWithOthers]
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.spokenAudio, options: audioOptions)
try? AVAudioSession.sharedInstance().setActive(true)
}
AVAudioSession.sharedInstance().requestRecordPermission({ permitted in
@@ -64,7 +64,7 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
videoInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoOutputSettings)
videoInput.expectsMediaDataInRealTime = true
pixelBufferInput = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: videoInput, sourcePixelBufferAttributes: attributes)
pixelBufferInput = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: videoInput, sourcePixelBufferAttributes: nil)
var angleEnabled: Bool {
for v in orientaions {
@@ -162,34 +162,11 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
var startingVideoTime: CMTime?
var isWritingWithoutError: Bool?
var currentDuration: TimeInterval = 0 // Seconds
func insert(pixel buffer: CVPixelBuffer, with intervals: CFTimeInterval) {
let time: CMTime = CMTimeMakeWithSeconds(intervals, 1000000)
if assetWriter.status == .unknown {
guard startingVideoTime == nil else {
isWritingWithoutError = false
return
}
startingVideoTime = time
if assetWriter.startWriting() {
assetWriter.startSession(atSourceTime: startingVideoTime!)
session.startRunning()
isRecording = true
isWritingWithoutError = true
} else {
delegate?.recorder(didFailRecording: assetWriter.error, and: "An error occurred while starting the video session.")
isWritingWithoutError = false
}
} else if assetWriter.status == .failed {
delegate?.recorder(didFailRecording: assetWriter.error, and: "Video session failed while recording.")
logAR.message("An error occurred while recording the video, status: \(assetWriter.status.rawValue), error: \(assetWriter.error!.localizedDescription)")
isWritingWithoutError = false
return
}
if videoInput.isReadyForMoreMediaData {
append(pixel: buffer, with: time)
isWritingWithoutError = true
}
let time: CMTime = CMTime(seconds: intervals, preferredTimescale: 1000000)
insert(pixel: buffer, with: time)
}
func insert(pixel buffer: CVPixelBuffer, with time: CMTime) {
@@ -201,16 +178,19 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
startingVideoTime = time
if assetWriter.startWriting() {
assetWriter.startSession(atSourceTime: startingVideoTime!)
currentDuration = 0
isRecording = true
isWritingWithoutError = true
} else {
delegate?.recorder(didFailRecording: assetWriter.error, and: "An error occurred while starting the video session.")
currentDuration = 0
isRecording = false
isWritingWithoutError = false
}
} else if assetWriter.status == .failed {
delegate?.recorder(didFailRecording: assetWriter.error, and: "Video session failed while recording.")
logAR.message("An error occurred while recording the video, status: \(assetWriter.status.rawValue), error: \(assetWriter.error!.localizedDescription)")
currentDuration = 0
isRecording = false
isWritingWithoutError = false
return
@@ -218,8 +198,10 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
if videoInput.isReadyForMoreMediaData {
append(pixel: buffer, with: time)
currentDuration = time.seconds - startingVideoTime!.seconds
isRecording = true
isWritingWithoutError = true
delegate?.recorder?(didUpdateRecording: currentDuration)
}
}
@@ -237,13 +219,25 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
isRecording = false
}
func end(writing finished: @escaping () -> Void){
func end(writing finished: @escaping () -> Void) {
if let session = session {
if session.isRunning {
session.stopRunning()
}
}
assetWriter.finishWriting(completionHandler: finished)
if assetWriter.status == .writing {
assetWriter.finishWriting(completionHandler: finished)
}
}
func cancel() {
if let session = session {
if session.isRunning {
session.stopRunning()
}
}
assetWriter.cancelWriting()
}
}
+4 -4
View File
@@ -20,7 +20,7 @@ import ARKit
*/
@available(iOS 11.0, *)
@objc public class ARView: NSObject {
private var parentVC: UIViewController?
private weak var parentVC: UIViewController?
private var recentAngle = 0
private var inputViewOrientation:[ARInputViewOrientation] = []
@@ -52,7 +52,7 @@ import ARKit
@objc init?(ARSceneKit: ARSCNView) {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: UIDevice.orientationDidChangeNotification, object: nil)
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
@@ -68,7 +68,7 @@ import ARKit
@objc init?(ARSpriteKit: ARSKView) {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: UIDevice.orientationDidChangeNotification, object: nil)
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
@@ -82,7 +82,7 @@ import ARKit
@objc init?(SceneKit: SCNView) {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: UIDevice.orientationDidChangeNotification, object: nil)
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
+64 -20
View File
@@ -12,13 +12,6 @@ import ARKit
import Photos
import PhotosUI
private var view: Any?
private var renderEngine: SCNRenderer!
private var gpuLoop: CADisplayLink!
private var isResting = false
private var ARcontentMode: ARFrameMode!
@available(iOS 11.0, *)
private var renderer: RenderAR!
/**
This class renders the `ARSCNView` or `ARSKView` content with the device's camera stream to generate a video 📹, photo 🌄, live photo 🎇 or GIF 🎆.
@@ -155,6 +148,11 @@ private var renderer: RenderAR!
view = SceneKit
setup()
}
//MARK: - Deinit
deinit {
gpuLoop.invalidate()
}
//MARK: - threads
let writerQueue = DispatchQueue(label:"com.ahmedbekhit.WriterQueue")
@@ -162,6 +160,13 @@ private var renderer: RenderAR!
let audioSessionQueue = DispatchQueue(label: "com.ahmedbekhit.AudioSessionQueue", attributes: .concurrent)
//MARK: - Objects
private var view: Any?
private var renderEngine: SCNRenderer!
private var gpuLoop: CADisplayLink!
private var isResting = false
private var ARcontentMode: ARFrameMode!
private var renderer: RenderAR!
private var scnView: SCNView!
private var fileCount = 0
@@ -220,10 +225,11 @@ private var renderer: RenderAR!
}
renderEngine = SCNRenderer(device: mtlDevice, options: nil)
renderEngine.scene = view.scene
gpuLoop = CADisplayLink(target: self, selector: #selector(renderFrame))
gpuLoop = CADisplayLink(target: WeakProxy(target: self),
selector: #selector(renderFrame))
gpuLoop.preferredFramesPerSecond = fps.rawValue
gpuLoop.add(to: .main, forMode: .commonModes)
gpuLoop.add(to: .main, forMode: .common)
status = .readyToRecord
} else if let view = view as? ARSKView {
@@ -243,10 +249,11 @@ private var renderer: RenderAR!
renderEngine = SCNRenderer(device: mtlDevice, options: nil)
renderEngine.scene = scnView.scene
gpuLoop = CADisplayLink(target: self, selector: #selector(renderFrame))
gpuLoop = CADisplayLink(target: WeakProxy(target: self),
selector: #selector(renderFrame))
gpuLoop.preferredFramesPerSecond = fps.rawValue
gpuLoop.add(to: .main, forMode: .commonModes)
gpuLoop.add(to: .main, forMode: .common)
status = .readyToRecord
} else if let view = view as? SCNView {
@@ -256,10 +263,11 @@ private var renderer: RenderAR!
}
renderEngine = SCNRenderer(device: mtlDevice, options: nil)
renderEngine.scene = view.scene
gpuLoop = CADisplayLink(target: self, selector: #selector(renderFrame))
gpuLoop = CADisplayLink(target: WeakProxy(target: self),
selector: #selector(renderFrame))
gpuLoop.preferredFramesPerSecond = fps.rawValue
gpuLoop.add(to: .main, forMode: .commonModes)
gpuLoop.add(to: .main, forMode: .common)
status = .readyToRecord
}
@@ -268,7 +276,7 @@ private var renderer: RenderAR!
renderer = RenderAR(view, renderer: renderEngine, contentMode: contentMode)
NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterBackground), name: Notification.Name.UIApplicationWillResignActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterBackground), name: UIApplication.willResignActiveNotification, object: nil)
}
@@ -513,6 +521,39 @@ private var renderer: RenderAR!
}
}
}
/**
A method that cancels recording a video 📹.
- parameter finished: A block that will be called when the specified `duration` has ended.
*/
@objc public func cancel() {
writerQueue.sync {
isRecording = false
adjustPausedTime = false
backFromPause = false
recordingWithLimit = false
pausedFrameTime = nil
resumeFrameTime = nil
DispatchQueue.main.async {
self.writer?.cancel()
if let path = self.currentVideoPath {
logAR.remove(from: path)
self.delegate?.recorder?(didCancelRecording: "Recording was cancelled manually.")
self.status = .readyToRecord
} else {
self.status = .readyToRecord
self.delegate?.recorder(didFailRecording: errSecDecode as? Error, and: "An error occured while stopping your video.")
}
self.writer = nil
}
}
}
/**
A method that exports a video 📹 file path to the Photo Library 📲💾.
@@ -724,7 +765,8 @@ extension RecordAR {
renderer.ARcontentMode = contentMode
self.writerQueue.sync {
var time: CMTime { return CMTimeMakeWithSeconds(renderer.time, 1000000) }
var time: CMTime { return CMTime(seconds: renderer.time, preferredTimescale: 1000000) }
self.renderAR?.frame(didRender: buffer, with: time, using: rawBuffer)
@@ -773,8 +815,10 @@ extension RecordAR {
self.adjustPausedTime = false
if self.pausedFrameTime != nil {
self.pausedFrameTime = self.adjustTime(current: time, resume: self.resumeFrameTime!, pause: self.pausedFrameTime!)
if self.pausedFrameTime != nil && self.resumeFrameTime != nil {
self.pausedFrameTime = self.adjustTime(current: time,
resume: self.resumeFrameTime!,
pause: self.pausedFrameTime!)
} else {
self.pausedFrameTime = time
}
+26
View File
@@ -0,0 +1,26 @@
//
// SSSS.swift
// ARVideoKit
//
// Created by Saul Moreno Abril on 01/05/2019.
// Copyright © 2019 Ahmed Fathit Bekhit. All rights reserved.
//
import Foundation
class WeakProxy: NSObject {
weak var target: NSObjectProtocol?
init(target: NSObjectProtocol) {
self.target = target
super.init()
}
override func responds(to aSelector: Selector!) -> Bool {
return (target?.responds(to: aSelector) ?? false) || super.responds(to: aSelector)
}
override func forwardingTarget(for aSelector: Selector!) -> Any? {
return target
}
}
@@ -418,7 +418,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = P5DZ3XQ9FJ;
DEVELOPMENT_TEAM = LXD85S9DW4;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
@@ -429,7 +429,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ahmedbekhit.ARVideoKit-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@@ -440,7 +440,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = P5DZ3XQ9FJ;
DEVELOPMENT_TEAM = LXD85S9DW4;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
@@ -451,7 +451,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ahmedbekhit.ARVideoKit-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@@ -19,8 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return ViewAR.orientation
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
@@ -115,7 +115,7 @@ class SCNViewController: UIViewController, ARSCNViewDelegate, RenderARDelegate,
}else if status == .denied || status == .restricted || status == .notDetermined {
let errorView = UIAlertController(title: "😅", message: "Please allow access to the photo library in order to save this media file.", preferredStyle: .alert)
let settingsBtn = UIAlertAction(title: "Open Settings", style: .cancel) { (_) -> Void in
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
@@ -123,11 +123,11 @@ class SCNViewController: UIViewController, ARSCNViewDelegate, RenderARDelegate,
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
})
} else {
UIApplication.shared.openURL(URL(string:UIApplicationOpenSettingsURLString)!)
UIApplication.shared.openURL(URL(string:UIApplication.openSettingsURLString)!)
}
}
}
errorView.addAction(UIAlertAction(title: "Later", style: UIAlertActionStyle.default, handler: {
errorView.addAction(UIAlertAction(title: "Later", style: UIAlertAction.Style.default, handler: {
(UIAlertAction)in
}))
errorView.addAction(settingsBtn)
@@ -106,7 +106,7 @@ class SKViewController: UIViewController, ARSKViewDelegate, RenderARDelegate, Re
}else if status == .denied || status == .restricted || status == .notDetermined {
let errorView = UIAlertController(title: "😅", message: "Please allow access to the photo library in order to save this media file.", preferredStyle: .alert)
let settingsBtn = UIAlertAction(title: "Open Settings", style: .cancel) { (_) -> Void in
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
@@ -114,11 +114,11 @@ class SKViewController: UIViewController, ARSKViewDelegate, RenderARDelegate, Re
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
})
} else {
UIApplication.shared.openURL(URL(string:UIApplicationOpenSettingsURLString)!)
UIApplication.shared.openURL(URL(string:UIApplication.openSettingsURLString)!)
}
}
}
errorView.addAction(UIAlertAction(title: "Later", style: UIAlertActionStyle.default, handler: {
errorView.addAction(UIAlertAction(title: "Later", style: UIAlertAction.Style.default, handler: {
(UIAlertAction)in
}))
errorView.addAction(settingsBtn)
+6 -7
View File
@@ -1,4 +1,6 @@
> An update for Swift 4.2 is coming soon :) -Ahmed
> Use [swift_5](https://github.com/AFathi/ARVideoKit/tree/swift_5) branch for projects written in Swift 5
> Use [master](https://github.com/AFathi/ARVideoKit/tree/master) branch for projects written in Swift 4.0
![intro image](http://www.ahmedbekhit.com/projects/repo-header-arvideokit.png)
@@ -52,9 +54,9 @@ To try the example project, simply clone this repository and open the `Examples`
## Installation
### Cocoapods
1. Add this line to your project's `Podfile`
1. Add this line to your project's `Podfile` (for Swift 4.2 projects)
```
pod 'ARVideoKit'
pod 'ARVideoKit','~> 1.51'
```
2. Install the pod
```
@@ -72,10 +74,7 @@ $ carthage update
```
### Manual
Drag the `ARVideoKit.framework` file as an embedded binary of your project targets. `ARVideoKit.framework` can be found in the `/Framework Build/` folder of this repository.
![Tutorial](http://www.ahmedbekhit.com/arvideokit_install_new.gif)
Or you may drag `ARVideoKit.xcodeproj` into your project and click the **+** button in the embedded binaries section of your project's target.
Drag `ARVideoKit.xcodeproj` into your project and click the **+** button in the embedded binaries section of your project's target.
![example embed framework](http://www.ahmedbekhit.com/embeddedBinary.png)
## Implementation
### Swift