Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Native Camera for Android & iOS [Open Source]

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

  1. mobile_esd

    mobile_esd

    Joined:
    Aug 13, 2019
    Posts:
    2
    Hi @yasirkula , congratulations and thank you very much for this plugin. I'm noticing a small reduction in quality and a larger file size of a picture using this plugin vs taking the same picture with the iOS photo app (iOS 14.2 on iPhone7). I'm using MaxSize = -1. What can you recommend to get the same quality for the picture as if it was taken with photo app? Is it possible to get the HEIC file? ... (I'm using your NativeGallery to write to iOS gallery)

    The photo of iOS photo app is HEIC 4,032 x 3,024 1.4MB
    The photo from this plugin is JPEG 3,024 x 4,032 8.5MB
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    You can set TakePicture's saveAsJPEG parameter to false for png but it will result in even larger filesize. NativeCamera doesn't have HEIC support. You can give this plugin a try if you want (you'll have to modify NativeCamera.mm as suggested).
     
  3. CeleDko

    CeleDko

    Joined:
    Jan 15, 2017
    Posts:
    26
    Hello, @yasirkula , Your plugin is great, with one exception. I am creating an application to create my memories and use your asset to quickly save photos of the user's memories. But it turns out that your asset just creates one image in the cache of my application and replaces that image after every shot. I upload images in memories through the paths where they are stored on the device. Because of this, wherever I have uploaded an image using the camera it is simply replaced with the last saved image. Please tell me how can I fix this?
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    You should rename the file that NativeCamera returns using File.Move. Make sure to generate a unique filename. You can use File.Exists to check if the target filename is already in use. I'd recommend you to move the file to Application.persistentDataPath (with a unique name, of course).
     
    Last edited: Dec 24, 2020
  5. CeleDko

    CeleDko

    Joined:
    Jan 15, 2017
    Posts:
    26
    Ok, I'll try, thanks for the quick response.
     
    yasirkula likes this.
  6. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    761
    Your asset is used in my project now to check camera permission in advance before starting main scene: AR Masker app.

     
    LYNXS_ and yasirkula like this.
  7. Snobo

    Snobo

    Joined:
    Nov 10, 2019
    Posts:
    3
    Hi there @yasirkula,
    we're using your plugin for a university project and while it works in the editor, I can't get it to work on my Android phone (Android 8, API level 26).

    At first I was trying to make your example code work, but there was never a prompt for access permissions and I quickly noticed that even checking for these permissions just never came back with any results.
    In the Unity Editor, checking permissions and setting the resulting string to a text on screen works with
    Code (CSharp):
    1. text.text += "Camera? " + NativeCamera.DeviceHasCamera() + "\n";
    .
    Doing the same thing on the phone does not show anything on the screen.

    I also noticed the app doing nothing for 5-10 seconds even before the Unity splash screen shows up since I've added the plugin. Could this also be related to the missing permissions request?

    At the moment I sadly can't debug the application on my phone (due to a problem with Rider, I think?) which made this whole "debugging" process quite tedious. Any and all suggestions would be welcome
     
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    I'm suspecting that there is an error message. It is likely caused by minification if you are using ProGuard. In that case, please see the FAQ in the first post. To see the error messages, you can use logcat in cmd, Unity's Android Logcat package or an ingame debug console like this.

    NativeCamera shouldn't affect app's startup time.
     
  9. Snobo

    Snobo

    Joined:
    Nov 10, 2019
    Posts:
    3
    Thank you so much for your quick reply, I'm a complete noob with putting a Unity App on Android and the Minify (Debug) checkmark was the culprit!
    Perfectly working now :)
     
    yasirkula likes this.
  10. viamaker

    viamaker

    Joined:
    Aug 1, 2017
    Posts:
    1
    Anyone got this problem when build to iOS 14?

    [Camera] Failed to read exposureBiasesByMode dictionary: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL}
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    When does this error occur? Does it prevent the plugin from functioning?
     
  12. ChuletaGames

    ChuletaGames

    Joined:
    Apr 7, 2020
    Posts:
    5
    Hi, First, thanks a lot for making this plugin freely available. It has been really really helpful.

    I have been using this plugin successfully in iOS and android using the camera to record a video for an AR project.

    When i record on IOS and then try to reproduce the video on Andriod i have this issue.

    On Unity Editor this appear.

    WindowsVideoMedia error 0x00000000 while reading https://teckdes.com/TestGuido/Uploads/wsrhX2OMmjeV41eIogou_Video.mp4

    Context: Unsupported stream type.
    Error details: La operacie completrrectamente.

    Track types:
    Audio Track, type: %10%16
    Video Track [480 x 360], type: H264
    Unknown Track : 72178C25-E45B-11D5-BC2A00B0, type: xbem
    Unknown Track : 72178C25-E45B-11D5-BC2A00B0, type: xbem
    Unknown Track : 72178C25-E45B-11D5-BC2A00B0, type: xbem



    PD: i dont know if maybe modify the quiality of record can help to change the video tracker and the type. Because i supuse the type of the video is h.264 because IOS doing in that way.

    Thnx For everything!!!
     

    Attached Files:

  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    If you download the video and then attempt to play the downloaded video (file:// uri), does it work? If it does, it can be a limitation of VideoPlayer that occurs while streaming videos from the web.
     
  14. reznorwill

    reznorwill

    Joined:
    Dec 3, 2020
    Posts:
    1
    Hi, how are you doing? First of all, thanks for the plugin!
    I have a question... is there any way of modify or setting the device camera quality?
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    RecordVideo takes a Quality parameter. TakePicture returns the high-res image provided by camera.
     
  16. NithishP

    NithishP

    Joined:
    May 3, 2019
    Posts:
    4
    hello, whenever i take picture using native camera, app closes and restarting. its happening at a 7 of 10 times. can you help me through this. i'm using both native gallery and native camera plugins.
     
  17. NithishP

    NithishP

    Joined:
    May 3, 2019
    Posts:
    4
    it is happening for me also. and i'm testing with 6gb RAM phone
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    This is out of my hands. I invoke the camera via standard Android API: calling startActivityForResult with an ACTION_IMAGE_CAPTURE Intent. The only reason for an unintended restart that I know of is device having low available memory. In your case, most of this 6 GB RAM might be used by other apps running in the background. Or your own app might be using most of this memory by using uncompressed Textures/AudioClips. Or Android OS might be limiting the maximum RAM allocated to your app (I'm unaware of such a mechanism, though).
     
  19. NithishP

    NithishP

    Joined:
    May 3, 2019
    Posts:
    4
    hello, thanks for reply
    in my case i have created new project imported from assetstore and took sample code from github and built. then also same issue, app is restarting again. and my device is having 40% free space and RAM is also free. can you help with this. and logs also show nothing.
     
    Suvajit likes this.
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    As much as I want to help, how can I help? Logs don't show anything useful and I can't reproduce the issue. I don't know the cause of the issue.
     
  21. naagi

    naagi

    Joined:
    Nov 27, 2014
    Posts:
    13
    Hi yasirkula, thank you very much for your assets, this one is a great help for me

    just a question, can i use this asset to record image that is projected to raw image object in the scene?

    I wanted to use it to record a user video during a video call on my apps
     
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Unfortunately not possible. User can record video via only native camera app's user interface and only after the recording is completed, the filepath is returned.
     
  23. naagi

    naagi

    Joined:
    Nov 27, 2014
    Posts:
    13
    thank you, this answer save me time to try it
     
    yasirkula likes this.
  24. seanphagen

    seanphagen

    Joined:
    Feb 22, 2021
    Posts:
    2
    Thanks for the awesome plugin!

    I'm wondering if there's something I need to do or change to save the EXIF data -- I've got a simple class set up that takes a photo and uploads it to a really simple Go webserver I've got running locally ( script here: https://gist.github.com/seanhagen/a5d583258c330a8ac8884bb4fcc8cc30 ).

    When I examine the photo after it's been uploaded I don't seem to have any of the location exif data, despite geo-tagging being turned on in my camera. All the camera data ( orientation, color space, phone info ) is there, but not the location stuff. Am I doing something wrong when taking the photo or when uploading the photo?
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  26. seanphagen

    seanphagen

    Joined:
    Feb 22, 2021
    Posts:
    2
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    No, it affects only iOS. On Android, I'm passing the image file returned by the camera app to Unity as is. I don't know if location data requires any additional setup, I haven't really researched about this topic.
     
  28. Sakshi_09

    Sakshi_09

    Joined:
    Jul 3, 2020
    Posts:
    8
    Hi,
    i am using your github project.
    https://github.com/yasirkula/UnityNativeCamera
    and i am facing one issue on latest android devices.
    After capturing image and pressing tick mark, my application is restarting automatically in Android Oreo. But it is working fine with any other mobiles but in some mobiles it is restarting the app.
    Please Help for the same.
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  30. Sakshi_09

    Sakshi_09

    Joined:
    Jul 3, 2020
    Posts:
    8
    No there is nothing in log file not any crash log but still after capturing image the application has restarted.
     
  31. ayygareth

    ayygareth

    Joined:
    Mar 4, 2020
    Posts:
    3
    Am I able to save the image captured in the application resources folder?
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Unity doesn't allow modifying Resources folder's contents after building the game.
     
  33. tomar8880

    tomar8880

    Joined:
    Jul 30, 2019
    Posts:
    2
    Hey, I used this plugin, It works great but can you help me in saving the recorded video in device.
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    If you mean saving to Gallery, then you can use NativeGallery.
     
  35. matheusPiovani

    matheusPiovani

    Joined:
    Mar 26, 2019
    Posts:
    1
    Also having the same problem as reported here, the app crashes sometimes after i take the photo(before the preview) and sometimes after accepting the image.
    I can only reproduce the problem in some low-end devices, the one that i used to test is a Moto G5 Plus(Android 8.1.0) with 2GB RAM.
    I searched the log for more info and the moment the app dies is:

    The full-log with the process that i believe that have to do with the error is attached.
     

    Attached Files:

  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    I've googled "Process has died: fore TOP" and "kill failed: No such process" but couldn't find useful results. I didn't notice any other relevant logs in the attached log file, as well. The fact that there is no crash dump in logcat makes me believe this is Android OS' doing.
     
  37. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    I'm working on a robotics project where the machine is run by an android phone and it needs to take pictures without prompting the user every now and then. Does the plugin somehow allow this?
     
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    No, the user must manually take the picture using the native camera app.
     
  39. Lu_Atar

    Lu_Atar

    Joined:
    May 16, 2017
    Posts:
    8
    Hello Yasirkula.

    First of all, thank you tremendously for providing your amazing assets, Camera and Gallery! We use these assets in our project, to build a room scanning app, and this saved us a lot of time of programming. I'll make sure to leave you a review and a donation.

    My question is, if it is possible to make the panorama capture accessible in NativeCamera, when calling TakePicture. The native camera in our target androids does support panorama capturing. However, this option is missing when opening the native camera in Unity. Any help or advice is much appreciated. Thank you!
     
  40. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  41. BenrajSD

    BenrajSD

    Joined:
    Dec 17, 2020
    Posts:
    25
    Hi, We are facing a issue like - if we take build (apk) from Unity is it working. Our requirement is to create a SDK and integrate with native android app. While creating gradle file, the .aar or .jar file is getting missed, so after integration camera not opens and throws error for com...... missing. Could you please check and get back. Even we add .aar at the time of integration, it is the same issue.
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    I'm unfamiliar with exporting Gradle projects. Can you try doing it in a new project?
     
  43. BenrajSD

    BenrajSD

    Joined:
    Dec 17, 2020
    Posts:
    25
    Tested with separate project, facing the same issue. We are using native gallery as well, that one is working fine, creating jar file which is required for connection between native application and sdk (export) file from unity. Only native camera have issue.

    Note: iOS SDK working fine while integrating with native iOS app, all dependencies are there with unityframework file.

    Please do update me if you have any idea. We tried convert the aar file to jar and some other approaches, nothing worked out.
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Both NativeGallery and NativeCamera have aar files, so I have no idea why NativeCamera's aar doesn't get included in the Gradle project. Unfortunately, my nonexistent knowledge of Gradle-exporting doesn't help either.
     
  45. Lu_Atar

    Lu_Atar

    Joined:
    May 16, 2017
    Posts:
    8
    Thank you for your answer! You are right, the panorama option in the native cameras is proprietary api, so far not accessible to external apps, and does not seem that it's going to be accessible in the near future. Shame.. Thanks again, and keep up the good work!
     
    yasirkula likes this.
  46. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    761
    Hi, After updating from 1.2.7 to 1.2.9 with Unity Package Manager I have not your folder (mentioned in changelog) in Project Settings.
     
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  48. cficara

    cficara

    Joined:
    Sep 27, 2017
    Posts:
    32
    Hi! First of all, thanks for such useful plug in!

    I'm extremely confused though, mainly due new Android Storage restrictions.

    Let's say I'm creating and app that creates short videos the user can later see as thumbnails. User taps any, video gets played in a tiny window.

    I'm recording a video, then I'm using
    Code (CSharp):
    1.  NativeGallery.SaveVideoToGallery(path, "test_folder", "test.mp4");
    to save the video. So far so good. Gets saved, folder and file is in gallery.

    Now, I'd like to retrieve these files, later on. I'm looking some sort of GetVideo( that_folder_path, any.mp4 ). How can I get back the paths of the files I saved using SaveVideoToGallery() ?

    Thanks a lot in advance.
     
    makaka-org likes this.
  49. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Quoting NativeGallery's FAQ and documentation:
     
    makaka-org likes this.
  50. cficara

    cficara

    Joined:
    Sep 27, 2017
    Posts:
    32
    Thanks a lot for the answer.

    I simply replaced NativeGallery.SaveVideoToGallery" with:
    Code (CSharp):
    1.  System.IO.File.Copy(path, Application.persistentDataPath + "/video.mp4", true);
    Then, getting the video is as simple as Application.persistentDataPath + "/video.mp4";

    I kinda found what I needed and works, but not sure if is the right way to do it.

    My next issue is finding out why Unity's Video Player breaks orientation on it. Any idea? Thanks a lot again!
     
    makaka-org likes this.