Search Unity

Native Camera for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, May 2, 2018.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'm not sure if video file will show up in Gallery if you just copy the video to persistentDataPath.

    You can call NativeCamera.GetVideoProperties(videoPath).rotation to learn how many degrees you need to rotate the video for correct orientation (e.g. you can rotate VideoPlayer around its z axis by that amount).
     
    cficara and makaka-org like this.
  2. cficara

    cficara

    Joined:
    Sep 27, 2017
    Posts:
    35
    Thanks a lot for that info!
     
  3. jairoandrety

    jairoandrety

    Joined:
    Feb 24, 2016
    Posts:
    6
    any way to do it in webgl?
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Perhaps WebCamTexture would work in WebGL.
     
  5. cficara

    cficara

    Joined:
    Sep 27, 2017
    Posts:
    35
    Im getting null results from NativeCamera.GetVideoThumbnail(). How videoPath is supposed to be formed? I'm just trying to get a thumbnail from a video located in my Resources folder. Thanks.

    PS: Is a .m4v video, is because of that?
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Assets in Resources folder aren't actual files in filesystem. You need to pass the file path of an actual video file. File.Exists must return true for that path.
     
  7. laymelek

    laymelek

    Joined:
    Apr 21, 2017
    Posts:
    16
    Hi,

    first of all thanks for the plugin... its great.

    I have a question. In Android what I click on the button and took the photo, android is showing me two buttons "cancel" and "ok". If I click OK it uses the photo i just took.. Is there a way to skip this step? I dont want to see these buttons. After i take the photo i want unity to use it immediately

    Thanks
    Levent
     
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Googling "ACTION_IMAGE_CAPTURE skip confirmation" confirms that there isn't a universal solution to this problem. I'd recommend you to ignore this inconvenience.
     
  9. Macode

    Macode

    Joined:
    Nov 28, 2013
    Posts:
    38
    Hi there, is it working on Linux Ubuntu OS?
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Only Android & iOS are supported.
     
    Macode likes this.
  11. janbaerts

    janbaerts

    Joined:
    Aug 30, 2020
    Posts:
    2
    Dear @yasirkula
    Thanks so much for your wonderful plugins, I have used them already a couple of times in some of my projects, they work very nicely! Hence I thought buying you a coffee was the least I could do :D.
    I have a question. Currently, when you use NativeCamera to take a picture in iOS, after you've taken it, it's showing "Use" and "Retake" in the bottom bar. Now, in this case, it's an app designed to be used by preschoolers who can't read yet. Is there anyway I can change these text buttons to show a green check mark and red cross, for example?
    Thanks so much in advance for your reply!
     
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  13. janbaerts

    janbaerts

    Joined:
    Aug 30, 2020
    Posts:
    2
    Neither will I :D, anyway, thanks for the clarification, I was expecting that was working that way... Enjoy your weekend!
     
    yasirkula likes this.
  14. dist1

    dist1

    Joined:
    Nov 24, 2021
    Posts:
    4
    Good afternoon. I have been trying to rotate the video in my scene (right now it's rotated at -90 and i need it at 270) I'm trying to change it with NativeCamera.GetVideoProperties(path).rotation but it tells me that I can't change the rotation because it's read only. How can i change the rotation?

    Thanks in advance
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    What is telling you that the video is read-only?
     
  16. dist1

    dist1

    Joined:
    Nov 24, 2021
    Posts:
    4
    I'll attach 2 images. The first one shows what i'm trying to do and the second one shows the error message i'm getting. Screenshot 2021-11-25 at 13.46.31.png Screenshot 2021-11-25 at 13.46.56.png
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    NativeCamera.VideoProperties is a readonly struct that holds information about the video. Think of it like right clicking a file in your operating system and selecting "See Info" or "Properties". These are just information, not modifiable values. You need to apply rotation manually, for example by rotating the VideoPlayer object.
     
  18. dist1

    dist1

    Joined:
    Nov 24, 2021
    Posts:
    4
    Alright, thanks.
    Rotating the VideoPlayer object in unity does not change the rotation of the video oddly enough. Do you have an idea of why this is the case?
     
  19. dist1

    dist1

    Joined:
    Nov 24, 2021
    Posts:
    4
    Got this figured out. Thanks for your help!
     
    yasirkula likes this.
  20. princegoel2000

    princegoel2000

    Joined:
    Nov 16, 2021
    Posts:
    2
    Hey! Thanks for this awesome work!!
    I added this code in my project and I need to add a confirm screen wherein the photo is shown and a retake or submit button is there. is there something similar that can be done in the native camera itself??
    Thanks for your help
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Some native camera apps already ask for Retake or Submit but I have no control over that. You'll really need to create that UI inside Unity. You can display a Texture2D in a RawImage and you can generate a Texture2D from an image path using NativeCamera.LoadImageAtPath.
     
  22. Riken_rds

    Riken_rds

    Joined:
    Apr 4, 2017
    Posts:
    49
    Hello, thanks for your hard work!
    i need to localize the text. how can i localize the text if you have any solution then help me, thanks
     

    Attached Files:

  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Hi, those texts come from the device's native camera app, I don't create them manually. So I'm guessing that they are localized with the device's language. If they aren't, you may try changing CultureInfo.CurrentCulture temporarily before launching the native camera to see if it makes a difference.
     
  24. Nakel

    Nakel

    Joined:
    Sep 28, 2017
    Posts:
    106
    Hello,

    Great asset as usual :D
    I wanted to ask if there is a simple way to add a watermark or text over the image when taking the picture ¿Is it possible to do it without creating another UI?
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Hi, it's unfortunately not possible with NativeCamera.
     
  26. DVish

    DVish

    Joined:
    Mar 15, 2022
    Posts:
    1
    Hi Yasir! Your plug-in is really awesome. Just a little thing i wanted to ask can i control flashlight through this?
     
    yasirkula likes this.
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Thank you! NativeCamera unfortunately doesn't give programmatic access to flashlight.
     
  28. UnityQueries

    UnityQueries

    Joined:
    Jul 6, 2021
    Posts:
    9
    Hi @yasirkula, Thank you so much for this Plugin. I am using this Plugin in my application and the application is able to access the device's native camera. I am also able to take pictures and record videos but these are not saved in Gallery.

    I have checked the Native Gallery for Android & iOS Plugin for saving the pictures and videos in Gallery.

    Can you please help me with how can I save the taken pictures and recorded videos in Gallery using the Native Camera for Android & iOS and Native Gallery for Android & iOS Plugins so that I have to share those through the social media applications.

    Thanks in advance.
     
    Last edited: Apr 12, 2022
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  30. Riken_rds

    Riken_rds

    Joined:
    Apr 4, 2017
    Posts:
    49
    i am trying with device's language but can't localize those text it's working on android perfect but not working on ios if any solution then let me know
    thank you
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  32. JammyDev

    JammyDev

    Joined:
    Feb 23, 2020
    Posts:
    2
    Hello! Thank you for making this it is such a great asset, and it is just what I need.

    I am just having a slight problem. I am running this on Android, Pixel 5. The picture that is taken is saved in internal memory. When I copy it out into the Persistent Data Path so I can manually open it it appears to be corrupted and I am unable to open the file. This is the code:

    upload_2022-5-12_22-25-38.png

    Any guidance would be greatly appreciated.
     
  33. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Your code looks fine to me. Can you call
    NativeCamera.LoadImageAtPath(path)
    and assign the returned Texture2D to a RawImage for debugging purposes?
     
  34. JammyDev

    JammyDev

    Joined:
    Feb 23, 2020
    Posts:
    2
    Thank you, I just installed NativeGallery to load the image using the path and it displayed on the Texture2D fine. So I just passed that texture back through into NativeGallery.SaveImageToGallery and it worked perfectly.

    upload_2022-5-12_23-14-9.png

    Thank you so much again, I was not expecting such a fast response! Have a great day / night!
     
    yasirkula likes this.
  35. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    Hi! Thanks so much for your plugins! We're looking to show the camera with a little button that opens the gallery in the bottom left, like in many messenger apps. I don't see this functionality anywhere - is this possible?
     
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Hi! This isn't possible with NativeCamera. The best you can do is create a UI in Unity with two buttons for Gallery and camera and use NativeGallery and NativeCamera for these tasks, respectively.
     
    tomkail_betterup likes this.
  37. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    We've found a rather nasty bug - on iOS, after launching the video app using Native Camera, attempts to play audio or video fail or lead to this error:
    AudioSampleProvider buffer overflow. 3779 sample frames discarded.
    The only fix we've found is to restart the app or to run AudioSettings.Reset(AudioSettings.GetConfiguration()) and unload all audio/video when the video camera is closed.
    Would be happy to forward you more details if we can help you diagnose it!
     
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  39. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    Ah it sounds like the same bug! Yes, we do need to stop/unload anything that plays audio after calling Reset.
     
  40. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'm a bit hesitant because while resolving the linked Issue myself, I didn't need to call AudioSettings.Reset (so calling that function mustn't be necessary in all cases) and I get the feeling that calling it will cause all running AudioSources to go silent. If my assumption is true, then AudioSettings.Reset will make things worse in cases like mine where calling it isn't necessary. I haven't had access to a Mac PC for years now, so I can't test anything on iOS myself. I don't know whether I should add AudioSettings.Reset to the camera callback or keep things as is (and add a FAQ entry instead).
     
  41. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    Yes, I think you're right about resetting potentially causing more issues. I don't know anything about native iOS programming so I can't offer any other solutions; but hopefully at least this thread will get picked up on Google for those who run into this issue in the future.
    Thanks!
     
    yasirkula likes this.
  42. zmatiaki

    zmatiaki

    Joined:
    Nov 21, 2018
    Posts:
    13
    Any Idea on how to activate black and white mode on camera? I am making an app for scanning documents
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @zmatiaki If the camera UI doesn't have an option for it, it's unfortunately not possible.
     
  44. Icyteck01

    Icyteck01

    Joined:
    Dec 27, 2016
    Posts:
    31
    Hello, i have a problem, when i open the camera to take pictures on ISO (iphone 8/9/10/11/12/13) memory leak and it crashes
     
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @Icyteck01 I'll do some research about this, thanks.
     
  46. Riken_rds

    Riken_rds

    Joined:
    Apr 4, 2017
    Posts:
    49
    hello thank you for providing amazing package
    i am using native camera and native gallery in my game. but i have fetching issue i am trying to capture image from camera then after restarting my app. same issue some time fetching in pick image from gallery. but most of fetching in camera. please help me to solve this. also i attach some logcat image for some more helping to fixing this.

    fetching in both platform android or ios
    i am checking with 4 GB ram android device(fetching issue).
    it's working fine in 8GB or above(working fine)

    thank you
     

    Attached Files:

    • s15.PNG
      s15.PNG
      File size:
      130.9 KB
      Views:
      145
    • s16.PNG
      s16.PNG
      File size:
      188.5 KB
      Views:
      145
    • s17.PNG
      s17.PNG
      File size:
      155.2 KB
      Views:
      142
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If you're creating Textures from the captured images, are you calling Destroy(oldTexture) when a Texture is no longer needed or are you calling NativeCamera.LoadImageAtPath without destroying the previously generated Textures?
     
  49. zkaka

    zkaka

    Joined:
    May 30, 2013
    Posts:
    5
    Hello, does this plugin support taking picture with ultra wide camera on iPhone 13 Pro?
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @zkaka Hi! I haven't tried it myself (and can't since I don't own iPhone) so it's unknown to me.