awalz / swiftycam Goto Github PK
View Code? Open in Web Editor NEWA Snapchat Inspired iOS Camera Framework written in Swift
License: BSD 2-Clause "Simplified" License
A Snapchat Inspired iOS Camera Framework written in Swift
License: BSD 2-Clause "Simplified" License
Thanks for your library.
Can you please add a delegate to display or indicate the(progress) duration of the video record in seconds while recording?
I wanted to subclass SwiftyCamButton to re-draw and make it @IBDesignable but was encountering a lot of issues. Not sure if there's a better way to do this. But I ended up had to edit SwiftyCamButton.swift to put #if !TARGET_INTERFACE_BUILDER around a whole bunch of stuff in the class to make my subclass work.
/// UIButton Subclass for Capturing Photo and Video with SwiftyCamViewController
open class SwiftyCamButton: UIButton {
/// Maximum duration variable
fileprivate var timer : Timer?
/// Initialization Declaration
override public init(frame: CGRect) {
super.init(frame: frame)
#if !TARGET_INTERFACE_BUILDER
createGestureRecognizers()
#endif
}
/// Initialization Declaration
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
#if !TARGET_INTERFACE_BUILDER
createGestureRecognizers()
#endif
}
#if !TARGET_INTERFACE_BUILDER
/// Delegate variable
public var delegate: SwiftyCamButtonDelegate?
/// UITapGestureRecognizer Function
@objc fileprivate func Tap() {
self.delegate?.buttonWasTapped()
}
/// UILongPressGestureRecognizer Function
@objc fileprivate func LongPress(_ sender:UILongPressGestureRecognizer!) {
if (sender.state == UIGestureRecognizerState.ended) {
invalidateTimer()
self.delegate?.buttonDidEndLongPress()
} else if (sender.state == UIGestureRecognizerState.began) {
self.delegate?.buttonDidBeginLongPress()
startTimer()
}
}
/// Timer Finished
@objc fileprivate func timerFinished() {
invalidateTimer()
self.delegate?.longPressDidReachMaximumDuration()
}
/// Start Maximum Duration Timer
fileprivate func startTimer() {
if let duration = delegate?.setMaxiumVideoDuration() {
//Check if duration is set, and greater than zero
if duration != 0.0 && duration > 0.0 {
timer = Timer.scheduledTimer(timeInterval: duration, target: self, selector: #selector(SwiftyCamButton.timerFinished), userInfo: nil, repeats: false)
}
}
}
// End timer if UILongPressGestureRecognizer is ended before time has ended
fileprivate func invalidateTimer() {
timer?.invalidate()
timer = nil
}
// Add Tap and LongPress gesture recognizers
fileprivate func createGestureRecognizers() {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(SwiftyCamButton.Tap))
let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(SwiftyCamButton.LongPress))
self.addGestureRecognizer(tapGesture)
self.addGestureRecognizer(longGesture)
}
#endif
}
Would be great to know if there's a better way to do this. Or if there can be native support for IBDesignable compatibility. Thanks!
Have you implemented the ability to switch the front facing and back facing cameras while the video is recording?
This is a style issue more than anything... The usual way of writing swift functions is with lower camel case. In the case of SwiftyCamViewControllerDelegate
, the functions are declared with upper camel case as in:
func SwiftyCamDidTakePhoto(_ photo:UIImage)
.
My suggestion would be to change the signatures to:
func swiftyCam(_ swiftyCam:SwiftyCamViewController, didTake photo:UIImage)
,
or something along those lines to align with Apple's practices for declaring delegate methods.
Some feedback for the SwiftyCam:
Disable Zoom when switching to front Camera (It doesn't zoom but the values change in the console, and when I switch to back camera and when I start to zoom it goes immediately at the highest value where I left from front camera.
Changing Icon when the light is on and off.
Disabling flash icon on front camera or taking a flash (like the iPhone camera or like snap)
When recording making an animation like Snapchat that you are recording (the red circle animated).
What do you think making a double tap to change the camera from back to front and vice versa.
Thanks
When push camera viewcontroller, I could see the following message.
Domain=AVFoundationErrorDomain Code=-11814 "Cannot Record" UserInfo={NSLocalizedRecoverySuggestion=Try recording again., NSLocalizedDescription=Cannot Record}
What should I fix?
I noticed a small bug when taking a picture with the front facing camera. The image that gets returned is rotated 180 degrees. This is only the case when taking the picture with the front facing camera, not the rear camera.
Have you implemented the ability to switch the front facing and back facing cameras while the video is recording?
In future versions could this be integrated.
Hey,
This is a wonderful library, thank you for this.
I have problem. I want to start my camera view controller with the front camera. If I invoke switchCamera()
in viewDidLoad
or viewWillAppear:animated
, the app crashes with the following message:
[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration
I assumed that switchCamera()
stopped the session when it was still being configured.
Then , I tried to set the currentCamera
property to .front
, but, that property's setter is private.
Am I missing a way to do this?
would be nice to be able to access the preview layer or camera session to further manipulate with the use of metadataOutputRectOfInterest
Perhaps I am using it incorrectly, but the delegates SwiftyCamButtonDelegate
and SwiftyCamViewControllerDelegate
are defined as strong references and were causing a retain cycle for me.
public weak var delegate: SwiftyCamButtonDelegate?
public protocol SwiftyCamButtonDelegate : class
fixed it for me.
When taking a front facing picture in the dark with flash on, the flash only shows for a brief second, and goes away before the picture is even taken, resulting in a dark photo. Any way to make the flash last until the picture is taken?
I am looking for help implementing Switching cameras between front and rear camera. This will require a rewrite to use AVCaptureVideoDataOutput and knowledge of AVAssetReader and AVAssetWriter. Any help would be appreciated!
Is there anyway this can be translated to swift 2.3? My whole app is in that version and I'm a bit of a newbie. Thanks!
is there any way to show the video duration when press on record button
does the recording video record all videos in portrait or just the problem when i read it with the AVplayer it does not know if the video portrait or landscape ??
I cant seem to get the cameras to switch properly. When i switch the camera, i just get a black screen and everything becomes unresponsive. Any way to fix this?
Hi @Awalz,
I commented some lines on SwiftyCamButton.swift file.
Like; let tapGesture and self.addGestureRecognizer(tapGesture) but single tap still working. This triggers longGesture.
Why? I Updated pod and i have this problem.
Thanks
@Awalz I love your project very much, but I'm having a problem. Instead of taking one photo and presenting the next viewcontroller the image. I want the user to hold down on the camera button and burst of images will be taken until they let go of the camera button. Once they let go, the array of images taken will be passed onto the next view controller. Can you please implement this
I want to create a button to save the photo after it's taken rather than it automatically being saved but I can't find the code that's making that happen. I was assuming it would be in the takePhoto() function but I can't pick up on it. Can you help? Thanks.
Confused your project with another. This is absolutely perfect! Thanks for your hard work. Issue closed. Best.
It would be great if there was at least an option to allow GPS meta data to be captured when taking a photo or video.
I am having issues getting the flash to work on the latest build. When I set flashEnabled = true , it does nothing. Any idea why this doesnt work?
EDIT: This ended up being something on my end. Sorry about that! Flash is working just as expected.
@Awalz
Is it possible to disable the shutter sound when the takePhoto
method is called?
In my usecase, while user is recording, at some point I also takePhoto
. That way at output I have both a video and a thumbnail photo. But I dont want the take photo
sound to go off.
I really appreciate the effort you put into this project and making it open source. Does the email you included on the README map to a PayPal account by chance?
Everything looks good when I post an image taken with the back camera, but when I take one with the front and upload it, its flips the image and crops it out of view. Do you know why this happening?
Will you add the SwiftyRecordButton into the library as you have in the demo?
Hey there,
When doubleTapCameraSwitch is enabled, tapping a few extra times consecutively causes an error:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration'
Thanks,
Qianen
While I love this component and how simple it is, I'm having quite a weird situation...
I've got everything working as per the demo example, but there is a thing that keeps me bothering, and it's creating the buttons in runtime with fixed frames. Since I hate working with constraints in code I decided to build a simple XIB and setup the buttons there.
The problem is that the previewView hides the buttons! From what I understand, the previewView is added later on, so it covers everything that's there; so adding the buttons after view did load manages to put the buttons above.
For now I'm gonna try moving the buttons to front, but is there any other way?
Camera freeze when making phone call. I need record silent video if user making call and reconnect audio after phone call ends.
Quick question - how do add a button to save images to the camera roll?
Fixed it.
func save() {
UIImageWriteToSavedPhotosAlbum(backgroundImage, nil, nil, nil)
}
The default behavior of the SnapChat camera is to only add the audio capture device and change the audio session category once video capture begins. This is a great UX and would love to see it added to SwiftyCam.
Hi,
It's possible to change the photo capture aspect ratio to 1:1 without cropping the output ?
Thanks
Would be a great alternative to CocoaPods and manual installation.
Andrew, i'm pressing to record button. But i guess it is giving late reaction.
I wait for about a second.
Is there a setting for this?
Thank you.
Hi Andrew,
I have a problem while video recording. As follows:
Very short Long press duration on SwiftyCamButton causes endless video recording.
In my debug session, I saw all UIGestureRecognizerState.began and UIGestureRecognizerState.ended state code blocks called. But recording never stopped
Thanks for help
I cloned DemoSwiftyCam and tried it on my iPhone 5S but the flash is not working. Is this a framework bug or can you recommend a way to implement it?
Also, comparing the usage instructions on README.md to the DemoSwiftyCam project, I can see that they are not coherent. Do you recommend to continue using the logic on DemoSwiftyCam?
Thanks in advance!
Would be nice to have the option to pick an image/video from the camera roll without having to exit the swifty cam controller. The functionality could be a camera roll icon and a swipe up to drag the camera roll up
How do I compress the video output? @Awalz
Can you add this feature?
I can reproduce this one-hundred percent of time. When I open the SwiftyCam view and fast-tap multiple times on the screen (to switch cameras) the app crashes after 5th or 6th tap on iPhone 6s. How could I prevent this from happening? Or is this a major issue maybe?
This is the error output:
2017-04-24 14:17:45.484928+0200 Slothy[7313:1391058] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration'
override func viewDidLoad() {
super.viewDidLoad()
maximumVideoDuration = 120.0
}
and after 2 minutes the video does not finish recording !
Is it possible to use the library only for photo capturing?
At the moment it requests permission to the microphone, but I do not want the users to see such request at all, as I will not record videos. Is this possible with the current implementation?
@Awalz
This happens randomly, but when I load the CameraViewController
, from time to time, the previewLayer
frame doesnt not extend to the bounds of my screen.
I havent done any modification to the library, simply subclassed SwiftyCamViewController
with these settings in viewDidLoad
Update** I dont know if this could perhaps be the problem previewLayer = PreviewView(frame: self.view.frame)
. I once read somewhere that you should always use view.bounds not frame but I have yet to test.
// In viewDidLoad
func cameraSettings() {
cameraDelegate = self
defaultCamera = .front
videoQuality = .medium
pinchToZoom = false
flashEnabled = false
doubleTapCameraSwitch = false
}
Hi,
I would like to take photos and record video in a different ratio other then 16:9
I would like it to be something more custom like 3:4.
When I open the camera view controller, the music that is playing immediately stops. When I manage to get music and the camera running, switching the camera from back to front freezes the preview. Is there a reason for this? Thanks in advance!
Hello,
I'm building a database with SwiftyCam and I've been having some problems uploading the videos to my server but the pictures work fine. So right now I want to just go with photo upload as I have removed the ability for users to create videos (I'd really love adding this back one day). Everything is fine but it's kind of creepy that my app asks for microphone permission but doesn't utilize it.
I've removed some of the privacy settings in the info.plist related to this, however as you may already know, it just removed the details/reason for asking for permission but the notification still persists. Are you able to tell me what triggers SwiftyCam to ask for this permission and how I can remove it for now?
I've tried removing some AVCaptureSession() stuff but it pretty much breaks everything - I'm hoping the solution is a one-liner.
Thanks for any help, I absolutely love all the hard work you put into this.
I am new to SwiftyCam, but love the idea. I wanted to add the SwiftyCamButton as it says in the READ.ME and I followed what it said, but when I run the app on my phone, all I see is the AVcaptureSession open, and I cannot see the button.
here is my code
`override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//SwiftyCam
let buttonFrame = CGRect(x: 200, y: 600, width: 200, height: 200)
let captureButton = SwiftyCamButton(frame: buttonFrame)
cameraDelegate = self
captureButton.delegate = self
}`
Any help would be appreciated thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.