SwiftUI 2.0 Building Custom Camera - Custom Camera View - AVFoundation - SwiftUI Tutorials

Поделиться
HTML-код
  • Опубликовано: 9 сен 2024
  • In this Video i'm going to show how to Build a Custom Camera View Using SwiftUI 2.0 | SwiftUI Camera | SwiftUI Creating Custom Camera View | SwiftUI | SwiftUI Custom Camera Controller | SwiftUI Camera App | How to Access Camera In SwiftUI | SwiftUI AVFoundation | SwiftUI AVCaptureSession | Xcode 12 SwiftUI.
    Source Code
    kavsoft.dev/Sw...
    Support Us By Contributions : donorbox.org/k...
    Support Us By Patreon : / kavsoft
    Support Us By Visiting the Link Given Below.
    ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. It's gives a great experience and I think you should give it a try too www.kite.com/g...
    My Xcode Version is 12.2
    My macOS Version is 11.0 Big Sur
    For Any Queries And Any Request For Videos Use The Given Link
    kavsoft.dev/#c...
    For More
    kavsoft.dev
    Instagram
    / _kavsoft
    Twitter
    / _kavsoft

Комментарии • 68

  • @finchandrew
    @finchandrew 2 года назад +19

    Hi all. Firstly thank you Kavsoft for this tutorial. It was easy to follow and helped me better understand the logic behind this kind of app building. I had an issue where UIImage(data: self.picData)! throws a nul error on unwrapping. I narrowed it down to the takePic() function. What solved it for me is moving the self.session.stopRunning() line to after the DispatchQueue. It seems that as it was, that is exactly before the DispachQueue, caused the data to be lost. I don't know If what I'm saying is absolute heracy as I am just starting but just though I would share it in case someone else met with this issue.

    • @nedorourke7587
      @nedorourke7587 2 года назад +2

      Hey Andrew, I'm having the same problem. Can you please elaborate on how you fixed it please. Thanks

    • @nateteuber6933
      @nateteuber6933 2 года назад +2

      @@nedorourke7587 Getting the same thing did you get it?

    • @abdulzkk
      @abdulzkk 2 года назад +2

      Thanks! had the same problem and this fixed it

    • @LDLefebvre
      @LDLefebvre 2 года назад +3

      Nice in addition I added to remove additional force unwrapping:
      DispatchQueue.main.asyncAfter(deadline: .now() + 0.5 {
      self.session.stopRunning()
      }

    • @Sophia-xd8kb
      @Sophia-xd8kb Год назад +1

      @@LDLefebvre thank you so much! I'm working on my bachelor's thesis and this specific problem has been driving me nuts for days!! now i can finally move on to the next one, haha

  • @hovannghia5598
    @hovannghia5598 3 года назад +5

    How to Building Custom record video - Custom Video View - AVFoundation - SwiftUI

  • @superus8r
    @superus8r Год назад +2

    Thank you so much for sharing the simple and straight forward example. Well done 👍

  • @bruhmoment3731
    @bruhmoment3731 3 года назад +1

    the preview on the right makes it so much easier to follow

  • @tuann2507
    @tuann2507 3 года назад +2

    Saving photo works on my Iphone but not for Ipad, could you please tell me how to do that? Thank you

  • @hongscave
    @hongscave 9 месяцев назад

    Man you are great. Thanks a lot for these videos.

  • @htetlynnhtun101
    @htetlynnhtun101 2 года назад

    Thank you for your hard work, Sir!. This video helps me alot!

  • @juanberon689
    @juanberon689 2 года назад +7

    Thanks a lot for this tutorial. I was following along until I noticed that I was not getting "pic taken..." in the output. My guess was that photoOutput() was not being called. I found a workaround in stackoverflow by putting a timer in self.session.stopRunning() in the func takePic() in this way DispatchQueue.main.async { Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { (timer) in self.session.stopRunning() } } . Does anybody know why this was needed? is there a better solution?

  • @user-be5ef7ht5h
    @user-be5ef7ht5h 3 года назад +3

    Great video!!!But How can I get a video from this Custom Camera?...

  • @SS-db5uw
    @SS-db5uw 3 года назад +3

    can u make a video about the feature of instagram to show the product by typing the photo ones??? pls
    btw nice video !

  • @lionsctn5053
    @lionsctn5053 3 года назад +1

    Great video!!! Been looking forward to this one

  • @anmac6910
    @anmac6910 6 месяцев назад

    Can we put a camera watermark doing this way ? because that's the only thing missing on ios...like in different formats such as:
    Feb 21, 2024 2:40:33 PM EST (for example). Also is AVcam the same thing as ios Camera app ? how is it different or same ?

  • @isaylmaz4263
    @isaylmaz4263 3 года назад +2

    Thx brother

  • @LukiStreli
    @LukiStreli Год назад +1

    Thank you, for this channel! Very good code, and i use some your examples in my work!
    I have some troubles on XCode 14.3.1 and target iOS 16+ 😭

    • @Kavsoft
      @Kavsoft  Год назад +1

      Can you explain the issue?

    • @LukiStreli
      @LukiStreli Год назад +2

      @@Kavsoft 11:40 - about after that, I noticed that I was getting a purple warning.
      At the same time, even at this stage, I did not receive a message in the console "pick taken..."
      As far as I understand, these warnings are related to the new work of threads in SwiftUI 4+. Thank you!
      struct CameraPreview: UIViewRepresentable {
      @ObservedObject var camera: CameraModel
      func makeUIView(context: Context) -> UIView {
      let view = UIView(frame: UIScreen.main.bounds)
      // WARNING! Publishing changes from within view updates is not allowed, this will cause undefined behavior.
      camera.preview = AVCaptureVideoPreviewLayer(session: camera.session) //

    • @user-ny5lu2dp1j
      @user-ny5lu2dp1j 9 месяцев назад

      I have the same issue
      @@LukiStreli

  • @d.k008
    @d.k008 3 года назад

    @kavsoft The example video shows that the camera opens immediately by clicking on the app icon. How to activate the same code only through the button ("Button (action: { ... }, label: { ... ") ???. There is a button on the TabBar, this button should open the camera... I'm just learning and I can't find the answer... Help!)

  • @lionsctn5053
    @lionsctn5053 3 года назад +2

    @kavsoft I was wondering could make a video on how to block a user and in return the user that is blocked can view the (current userid) post or send them messages. I want to develop my skills to see how this works? Thank you

  • @user-ry6ix2mr8y
    @user-ry6ix2mr8y 3 года назад +8

    Kavsoft - when the screen is oriented, the camera borders break - how to fix it?? pls help

    • @thakker_family
      @thakker_family 3 года назад

      any idea?

    • @LDLefebvre
      @LDLefebvre 2 года назад

      Found a solution?

    • @michaelceryak6905
      @michaelceryak6905 9 месяцев назад

      I had the same question and figured it out a solution. I added a binding var inside CameraView of type UIDeviceOrientation?. In the SwiftUI parent view, .onAppear() and .onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) I set the orientation to UIDevice.current.orientation. This triggers the updateUIView() method to be called where you can reset the preview's frame and videoOrientationAngle.

  • @stationdev
    @stationdev 2 года назад

    Do you know if it is possible to somehow crop the captured image by detecting the rectangle? how to get only part of a card

  • @denislevkovich
    @denislevkovich Год назад

    Fantastic tutorial!

  • @puffyandpudding
    @puffyandpudding 3 года назад +2

    Hi Balaji, thanks for making this video! I have one problem I couldn't figure out and it's been bothering me for days. When I wrap the CameraPreview (which is a UIViewRepresentable) inside a NavigationView, the view takes more than 10 seconds to load. Could you please help me figure out why this is the case?

    • @puffyandpudding
      @puffyandpudding 3 года назад +1

      Update: The CameraPreview is a also a TabView Item.

  • @basukhadka
    @basukhadka 2 года назад +2

    when I try to go to my camera scene it freezes and gives me an error saying device found nil

    • @pianoprodigy23
      @pianoprodigy23 2 года назад +1

      I have the same issue. Any fix for this?

    • @pianoprodigy23
      @pianoprodigy23 2 года назад +5

      Update: I solved by only specifying the "for" parameter --> let device = AVCaptureDevice.default(for: .video)

    • @basukhadka
      @basukhadka 2 года назад

      @@pianoprodigy23 oh thanks, very helpful

    • @jacoblucas6035
      @jacoblucas6035 2 года назад

      @@pianoprodigy23 Thank you!

    • @veljkobazalac
      @veljkobazalac Год назад

      @@pianoprodigy23 Thanks :D

  • @Simon-ro8nh
    @Simon-ro8nh 3 года назад

    Great tutorial! Very helpful! Thank you!

  • @somersmatthews2749
    @somersmatthews2749 3 года назад +1

    Great Video

  • @emrecanacer
    @emrecanacer 3 года назад

    Great video! Thank you very much really appreciated 🙌🏻

  • @ylxh.1
    @ylxh.1 Год назад

    Hi !!! Firstly thank you for video. I have issue when save image. This picture has saved not the lates images (n-1). And alway on the firts picture is empty. Pls help me resolve that, thanks you.

  • @hashankannangara8723
    @hashankannangara8723 3 года назад

    Awesome that is a very important video. Thanks.

  • @alekseiwe
    @alekseiwe Год назад

    Cool 🎉

  • @basukhadka
    @basukhadka 2 года назад

    I keep on running into 2 issues that Kees on saying that "CameraModel has no initializer", and that "type CameraModel cannot conform to ObservableObject" does anyone know how to fix this???

    • @Kavsoft
      @Kavsoft  2 года назад

      Just in case check whether you used struct instead of class for CameraModel?

    • @LDLefebvre
      @LDLefebvre 2 года назад

      for me I had forgotten "!" at the end of a variable, I had the same issue and this fixed it: @Published var preview: AVCaptureVideoPreviewLayer!

  • @user-hy5hu1et4f
    @user-hy5hu1et4f Год назад

    Hello, do you need to pay for the source code, I can't open it

  • @user-xr1sh1mv4v
    @user-xr1sh1mv4v 3 года назад +1

    Hello i'm watching your videos i want swiftui imageviewer with zoom and pinch

    • @LDLefebvre
      @LDLefebvre 2 года назад

      Did you found a way to do this?

  • @user-ny5lu2dp1j
    @user-ny5lu2dp1j 9 месяцев назад

    About the CameraPreview, I came across issue.
    camera.preview = AVCaptureVideoPreviewLayer(session: camera.session) //xcode said: Publishing changes from within view updates is not allowed, this will cause undefined behavior.
    camera.preview.frame = view.frame
    camera.preview.videoGravity = .resizeAspectFill
    camera.session.startRunning() //xcode said: -[AVCaptureSession startRunning] should be called from background thread. Calling it on the main thread can lead to UI unresponsiveness
    view.layer.addSublayer(camera.preview)
    xcode14.

    • @Kavsoft
      @Kavsoft  9 месяцев назад

      Replace dispatchTask from .userInitiated to .background.
      Also check out this updated version!
      ruclips.net/video/_GGDueorwEA/видео.html

    • @user-ny5lu2dp1j
      @user-ny5lu2dp1j 9 месяцев назад

      Thanks a lot@@Kavsoft

    • @henna._.0396
      @henna._.0396 5 месяцев назад +1

      Where do you replace? I am having the same issue I can't find out still how to solve it. help!!@@Kavsoft

    • @ricardoag992
      @ricardoag992 2 месяца назад

      @@henna._.0396 me too

  • @lovelymusicnow4404
    @lovelymusicnow4404 Год назад

    how come you guys never out film anything other then your keyboard SMH