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. wellzito

    wellzito

    Joined:
    Mar 29, 2017
    Posts:
    5

    After the latest updates, do you think it's possible to start recording automatically nowadays? The stop was simple to do, just set the time I want. But I wanted to auto start the recording.
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Try adding
    if( !imageMode ) [imagePicker startVideoCapture];
    after this line and see how it goes. This isn't possible on Android.
     
  3. wellzito

    wellzito

    Joined:
    Mar 29, 2017
    Posts:
    5

    Hi, thanks for replying! Too bad you can't have the automatic fire control on Android. However, I wanted to know if it is possible to have control of the time counter after I manually press the record button. In this case, I want to set and save the countdown.
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    If you're asking about retrieving the remaining value of maxDuration (e.g. 2 seconds of maximum-5-second-long recording has passed), I didn't see a function for it. On iOS, these are the only available functions provided by the operation system: https://developer.apple.com/documentation/uikit/uiimagepickercontroller?language=objc. On Android, you can't rely on anything at all since different stock/app store camera apps can behave differently and there isn't a unified API for them. Some camera apps don't even respect maxDuration :eek:

    If instead you're talking about a 3-2-1 countdown, I haven't seen a method to get its current value or set its duration. Please see the link I've provided for all available functions.
     
  5. shoib_akthar

    shoib_akthar

    Joined:
    Oct 21, 2021
    Posts:
    4
    Hi @yasirkula ,Is it possible to prompt only camera permission but not access to images and video in Android as I'm not storing anything in the device.Im only using camera For AR.
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Some Android devices allegedly store the full-resolution image/video in Gallery instead of the app cache, so we need the Gallery permission to retrieve it from there.
     
  7. shoib_akthar

    shoib_akthar

    Joined:
    Oct 21, 2021
    Posts:
    4
    I understand but is possible to only show camera access?
     
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    You must modify the source code in Android Studio and rebuild NativeCamera.aar for it.
     
  9. eagleeyez

    eagleeyez

    Joined:
    Mar 21, 2013
    Posts:
    402
    Hi there, why is there no unity demo scene in the package? That would be great thanks.
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  11. eagleeyez

    eagleeyez

    Joined:
    Mar 21, 2013
    Posts:
    402
  12. eagleeyez

    eagleeyez

    Joined:
    Mar 21, 2013
    Posts:
    402
    Just make a demo, or is that so hard?
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  14. eagleeyez

    eagleeyez

    Joined:
    Mar 21, 2013
    Posts:
    402
    :) Anyone maybe have a small example of just a simple full screen camera and have that picture saved to a unity texture. I am then going to use another asset to send this picture over wifi to a unity app running on the pc
    thank you.
     
    yasirkula likes this.
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    You can add this function to a script in your scene and connect it to e.g. a button's On Click event:
    Code (CSharp):
    1. public void TakePicture( int maxSize = 1024 )
    2. {
    3.     NativeCamera.TakePicture( ( path ) =>
    4.     {
    5.         if( path != null )
    6.         {
    7.             // 1) Either send the image file at path to another PC directly (image size might be a few MBs depending on camera quality)
    8.            
    9.             // 2) Or, create a Texture2D (scaled down if needed to satisfy maxSize pixels in each dimension) from the image file and send it to another PC
    10.             Texture2D texture = NativeCamera.LoadImageAtPath( path, maxSize );
    11.             if( texture == null )
    12.             {
    13.                 Debug.Log( "Couldn't load texture from " + path );
    14.                 return;
    15.             }
    16.            
    17.         }
    18.     }, maxSize );
    19. }
     
  16. Riken_rds

    Riken_rds

    Joined:
    Apr 4, 2017
    Posts:
    49
    I am facing issue in android 13 .
    While using camera for taking pictures it's redirect to native permission screen event is permission is granted .this happens only in Android 13.
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  18. Shreenath1322

    Shreenath1322

    Joined:
    Apr 7, 2016
    Posts:
    7
    is it possible to open both the front and back camera at the same time in unity?
     
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
  20. waqarahmed1

    waqarahmed1

    Joined:
    Mar 21, 2023
    Posts:
    1
    Hi @yasirkula
    Awesome package and easy to use.
    Is it possible to turn off the switching of camera on IOS, in my use case I want only front camera ?
    Is it possible to save the images and videos in "Files" folder using NativeGallery. I can save the images and videos in "Photos" but I want to save them in "Files" as well ?
    Is it possible to give the desired name to a file before saving it using NativeGallery ?
    Kindly please help.
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Hi @waqarahmed1, for the first question, please see this thread. You can't save files to Files using NativeGallery but I believe you can do that with NativeFilePicker. You can specify a custom filename in NativeGallery's save function but if you'd like, you can also File.Copy the returned path to a new path with the desired name.
     
  22. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    251
    hey i get null path after taking the image
     
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Can you spot useful logs, is it reproducable on an empty project, does something visibly go wrong in the camera app?
     
  24. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    251
    its a very basic URP project, just a single script with your example code a few posts above. Dont thing its a permission thing cause the camera opens but then returns empty path..
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    It unfortunately doesn't happen on my Android phone (Galaxy S8). My guess is that it happens on some specific devices and doesn't output useful logs to logcat. I don't think NativeCamera is compatible with that device for reasons I'm unaware of.
     
  26. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    251
    This is beyond disappointing :/
     
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,716
    Yeah, I'm using the standard way of opening the camera. It's annoying that some devices just don't want to comply with Android's standards. They usually don't provide useful information in logcat either. They just fail to work.