Search Unity

Native Gallery for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Feb 28, 2018.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Are they importing the images saved via NativeGallery or any arbitrary image in Gallery? If NativeGallery.LoadImageAtPath is used, the orientation should be preserved. If the orientation is still not preserved, then there "may" be an informative error message in logcat.
     
  2. tz

    tz

    Joined:
    Oct 13, 2007
    Posts:
    91
    This would be arbitrary images selected via their photo app, imported via NativeGallery.LoadImageAtPath() as you surmise (i.e. not originally saved out via NativeGallery).
    Note: I believe we had a user tell us this was only happening with images they sourced from the device's camera, not ones that they saved to their photo album from the internet.


    We received two emails today from Samsung S10 owners running recent Android builds )with additional instances on Samsung previously). We've had one report from someone on a Huawei Mate 30 Pro.

    We can't repro it here, but will try to think of a way to get more info.
     
    Last edited: Jan 28, 2020
  3. RafaVaz

    RafaVaz

    Joined:
    Nov 16, 2017
    Posts:
    2
    Hi @yasirkula, thanks for creating this plugin and for being so active on its forum! I'm trying to get that last picture taken from the camera of an android phone, but I'm running into issues retrieving them. My code is based on the example and simple:

    Code (CSharp):
    1.  public void GetLatestImage()
    2.     {
    3.  
    4.         Material material = quad.GetComponent<Renderer>().material;
    5.         material.color = Color.white;
    6.  
    7.         NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
    8.         {
    9.             material.color = Color.green;
    10.             if (path != null)
    11.             {
    12.                 Debug.Log($"<color=green>Image path: {path} </color>");
    13.  
    14.                 material.color = Color.cyan;
    15.                 // Create Texture from selected image
    16.                 Texture2D texture = NativeGallery.LoadImageAtPath(path, maxImageSize);
    17.                 if (texture == null)
    18.                 {
    19.                     Debug.Log("Couldn't load texture from " + path);
    20.                     material.color = Color.red;
    21.                     return;
    22.                 } else
    23.                 {
    24.  
    25.                     Debug.Log("<color=blue>texture found </color>");
    26.                 }
    27.  
    28.                 if (!material.shader.isSupported) // happens when Standard shader is not included in the build
    29.                     material.shader = Shader.Find("Legacy Shaders/Diffuse");
    30.  
    31.                 material.mainTexture = texture;
    32.  
    33.             } else
    34.             {
    35.                 Debug.Log("<color=yellow>No path set</color>");
    36.                 material.color = Color.yellow;
    37.             }
    38.         }, "Select a PNG image"); //, "image/png"
    39.  
    40.         Debug.Log("Permission result: " + permission);
    41.  
    42.     }
    43.  
    I use both Debugs and material colors to see which part of the code has run, but it seems that when on device, it just skips the code from GetImageGallery, as none of the debugs inside show up. The final permission result debug does appear correctly with a 'Granted' permission.I went deeper and noticed that the savePath inside 'GetMediaFromGallery' is being set. Looking though the fourm, it seems the issue has been brought up before, but I'm not sure if a solution was found. Both my debug log and logcat have found no errors. I've made sure that I have set write permission to External (SD card). I'm using Unity 2019.3.0f5 and using Android version 10. Any suggestions on what this might be?

    Thanks,
    Rafa

    PS I tried copying the example code directly and face the same issue; the debugs inside of the callbacks are not being triggered...
     
    Last edited: Jan 29, 2020
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    I'm sorry to hear that. Is it possible for you to test this code on another Android device (preferably with a different brand) or on an emulator and see if the issue is persistent? If it is, could you tell me on which devices you experienced this issue?
     
  5. tz

    tz

    Joined:
    Oct 13, 2007
    Posts:
    91
    Additional info: This appears to be an issue with images on Samsung phones that are taking then storing photos in HEIF/HEIC format. Android 9+ seems to support HEIF, so this may explain why we've also had a report on a Huawei P30.

    There is a settings toggle in the Samsung Gallery app called "Convert HEIF images when sharing" that may be why we're seeing it reported only by some users and not others. I will test this afternoon once I'm in a running state again.

    TLDR: This appears to be related how NativeGallery handles metadata associated with HEIF/HEIC image formats on Android 9+.
     
  6. RafaVaz

    RafaVaz

    Joined:
    Nov 16, 2017
    Posts:
    2
    @yasirkula Hi, I've tested this on a Samsung S6 and on a Huawei Mate 20x with the example code; and in both cases the same occurred. I suspect it might be the unity version, though unfortunately in my project we can't change that at this moment.
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    @tz @RafaVaz Thanks for the feedbacks. I'll see what can be done about these issues but no promises for now.
     
    tz likes this.
  8. ThePurpleSprinkles

    ThePurpleSprinkles

    Joined:
    Sep 22, 2018
    Posts:
    16
    @yasirkula Quick question, I'm new to Unity and I am using the Unity Remote 5 app (iOS) to test my software, but a request to pick a photo will not work on it. After doing some research, it turns out that when using Remote 5, the program will recognize the device as a PC, not a phone. This is why it is not working, but I have no other way to test this other than Remote 5. Any suggestions?
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    You are right, it won't work with Unity Remote. There is no workaround for it. However, the plugin should work fine on emulators.
     
  10. Ehtisham007

    Ehtisham007

    Joined:
    Jan 8, 2018
    Posts:
    1
    What string should we write in path if we want to load image from gallery
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
  12. ThePurpleSprinkles

    ThePurpleSprinkles

    Joined:
    Sep 22, 2018
    Posts:
    16
    Thanks for the reply, I didn't even think of emulating it.
     
  13. MaryamKamel

    MaryamKamel

    Joined:
    Feb 5, 2016
    Posts:
    22
    @yasirkula i upgraded to 2019.3 and used the latest package version on github and its working fine :D thanks for your great work and support (y) keep it up ;)
     
    yasirkula likes this.
  14. skoteskote

    skoteskote

    Joined:
    Feb 15, 2017
    Posts:
    87
    Amazing asset, thank you so much for making this! I trying to figure out video rotation on iOS, as the videos I access are rotated 90° to the left. I saw there is a NativeGallery.GetVideoProperties(string path).rotation, but I fail to see how I apply that, as VideoPlayer.url has no rotation property? Should I use it to rotate the actual RawImage I'm displaying the Render Texture to?

    Code (CSharp):
    1.             NativeGallery.Permission permission = NativeGallery.GetVideoFromGallery((path) =>
    2.             {
    3.                 if (path != null)
    4.                 {
    5.                     //Rotation here
    6.                     videoPlayer.url = "file://" + path;
    7.                 }
    8.             }, "Select a video");
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Yes, that's what I'd recommend.
     
    skoteskote likes this.
  16. AlexNTapp

    AlexNTapp

    Joined:
    Jan 7, 2020
    Posts:
    2
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Oh, sorry; it is a low priority for me right now. I actually kinda forgot about it, lol. No promises for the near future.
     
  18. Sidji

    Sidji

    Joined:
    Feb 22, 2017
    Posts:
    2
    hello thank for your plugin, its very helpfull :D ...
    ----
    i want to ask about permisiion, in my apps it always ask permision when the application first launch (at unity splash screen) even i chose denny and i restart again and it keep show ask permision, its possible to ask permision only when user open a gallery?? , not at first application launch ...

    thank you :)
     
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Sidji likes this.
  20. Sidji

    Sidji

    Joined:
    Feb 22, 2017
    Posts:
    2
    allright, thanks you for your solution , its work now :D

    another question and suggestion for my code ,

    your documentation say :"GetImageFromGallery/GetVideoFromGallery functions call RequestPermission internally and execute only if the permission is granted" , based on that ,i dont need call "RequestPermission" function right? ...

    so i make a imagepicker method like this :

    Code (CSharp):
    1.  private void PickImage()
    2.         {
    3.             //check is galery ready to open
    4.             if (!NativeGallery.IsMediaPickerBusy())
    5.             {
    6.                 //always check permision, maybe sometime user change setting value
    7.                 switch (NativeGallery.CheckPermission())
    8.                 {
    9.                     //if denied then, guide user to give permision on setting window
    10.                     case NativeGallery.Permission.Denied:
    11.                             if (NativeGallery.CanOpenSettings())//check is can open?
    12.                             {
    13.                                 NativeGallery.OpenSettings();
    14.                             }
    15.                             else
    16.                             {
    17.                                 // cannot open setting
    18.                             }
    19.                         break;
    20.                     default:
    21.                     // if grant or should ask, then call getimage API (request permision inside)
    22.                         NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
    23.                         {
    24.                             if (path != null)
    25.                             {
    26.                                 // Create Texture from selected image
    27.                                 profilImage = NativeGallery.LoadImageAtPath(path, 512, false, false, false);
    28.                                 if (profilImage == null)
    29.                                 {
    30.                                     //fail load image
    31.                                     return;
    32.                                 }
    33.  
    34.                                 rawImage.texture = profilImage;
    35.                                 isImageChage = true;
    36.                             }
    37.                             else
    38.                             {
    39.                                 //nothing image selected
    40.                             }
    41.                         }, "Select Image (512x512)", "image/*");                      
    42.                         break;
    43.                 }
    44.              
    45.             }
    46.             else
    47.             {
    48.                 //galery cannot open
    49.             }
    50.         }
    is okay i make code like that? , i just make sure that my code is right way ...

    thanks :D
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Your code looks good, well done!
     
  22. blaumeisje

    blaumeisje

    Joined:
    Dec 31, 2017
    Posts:
    19
    I deleted my old post as it is obsolete. Native Gallery is working fine now. I even don't know, which parameter was wrong, as I changed so many, but now it works. Again, Thanks a lot for the great tool.
     
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Glad the issue is somehow resolved! I was testing the plugin on an empty project with the closest setup I had (2019.1.8 and an x86 Android 9 emulator) and I didn't spot any issues with that setup.
     
  24. Teixeira1971

    Teixeira1971

    Joined:
    Feb 23, 2018
    Posts:
    1
    e você me orienta como posso escolher o local para salvar o vídeo? Tanks
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    NativeGallery.SaveVideoToGallery takes an album name, you can specify the target album via that parameter.
     
    skoteskote likes this.
  26. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Hi @yasirkula

    How can I know that if image or video save to gallery successfully?
     
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    You can use the optional
    MediaSaveCallback callback
    parameter, please see the README file for more info.
     
  28. Lordmin

    Lordmin

    Joined:
    Mar 9, 2017
    Posts:
    62
    1. I took a picture with 'Built-in camera app' on iPhone / iPad.

    2. <NativeGallery.GetImageFromGallery in Native Camera for Android and iOS assets>
    I used the function to import photos from album.

    3. '?' The image is loaded.

    4. Using the <NativeCamera.TakePicture> function, the texture loads very well.


    Why is that?

    Is there a way to fix it?

    I look forward to your good answer.

    Thank you very much for providing good assets.
     
    Last edited: Feb 28, 2020
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
  30. Lordmin

    Lordmin

    Joined:
    Mar 9, 2017
    Posts:
    62

    Texture2D NativeImage = NativeGallery.LoadImageAtPath(path, -1);

    My code is already using it like this currently.
    Where is the problem?

    <iOS Xcode Debug Log>
    libpng error: [00][00][00][00]: missing IHDR
     
    Last edited: Mar 2, 2020
  31. unadamlar

    unadamlar

    Joined:
    Jul 7, 2015
    Posts:
    10
    My app requests permission on startup I'm not exactly sure whether it is because of this asset. Is it? If it is, how can I make it so that it only requests the permission when the user actually is going to upload their image.
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    @Lordmin I haven't seen this error before. Perhaps the camera app somehow saves HEIC images with PNG extension? Googling the issue didn't yield any useful results, so I don't know what is causing this issue and don't think that I can fix it.

    @unadamlar Setting the Write Permission to "External (SDCard)" will result in this behaviour but yes, it is necessary for NativeGallery to work. You can hide the initial permission dialog, though. Please see the first paragraph of this documentation: https://github.com/yasirkula/UnityAndroidRuntimePermissions#how-to
     
  33. unadamlar

    unadamlar

    Joined:
    Jul 7, 2015
    Posts:
    10
    yasirkula likes this.
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    I couldn't reproduce this issue with the following 3 sample HEIF images on my S8 (Android 9). NativeGallery reported that the first image had no EXIF orientation data whereas the other ones had 90-degree clockwise rotation EXIF data. But they were all loaded with proper orientation. Toggling "Convert HEIF images when sharing" or picking the image via Gallery or Photos apps had no effect. Until I can get my hands on a device that has this issue, I don't think I will be able to resolve this issue.

    https://github.com/strukturag/libheif/blob/master/examples/example.heic
    https://github.com/d2phap/ImageGlass/issues/559#issue-467104430
    https://github.com/d2phap/ImageGlass/issues/559#issuecomment-511187283

    My device's camera app doesn't have HEIC support, so I had to find sample images online. If you find HEIC images that the issue can be reproduced with, please send them to me.
     
  35. meddmi

    meddmi

    Joined:
    May 11, 2017
    Posts:
    4
    Hi @yasirkula.

    I try to use your plugin based on a code example. I found that on my test device (Samsung Galaxy S9 with Android 10 on board) function NativeGallery.LoadImageAtPath couldn't return a texture and has an internal issue.

    After a small investigation, I guess an issue related to changes in Android 10, and an issue with File.ReadAllBytes. Also I have found your other plugin UnitySimpleFileBrowser, where, I guess, you describe the same issue with Android 10.

    So, could you confirm my assumption? If I'm right, have you a plan to fix this issue in NativeGallery? Or, maybe you know a way, how I can try to fix it directly from Unity?

    P.S. Thanks for great plugin.
     
  36. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    77
    cant save image on Android 10
     
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
  38. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    77
    no. lagcat empty in my case
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Hmm, I can't really tell why this is happening. It is an unknown issue.
     
  40. AlexNTapp

    AlexNTapp

    Joined:
    Jan 7, 2020
    Posts:
    2
    if anyone needs to open just the gallery without picking a photo:

    iOS:
    in NativeGallery.mm(found in Plugins>NativeGallery>iOS) just add at the top
    + (void)openGallery;

    then add somewhere in the @implementation UNativeGallery
    + (void)openGallery{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"photos-redirect://"]];
    }

    finally at the bottom
    extern "C" void _NativeGallery_OpenIosGallery(){
    return [UNativeGallery openGallery];
    }

    then in NativeGallery.cs where the other DllImports are, add
    [System.Runtime.InteropServices.DllImport( "__Internal" )]
    private static extern void _NativeGallery_OpenIosGallery();

    then add a static method like
    public static void OpenGallery()
    {
    #if !UNITY_EDITOR && UNITY_IOS
    _NativeGallery_OpenIosGallery();
    #endif
    }


    Android:
    you'll need to rebuild the jar
    the code you need to add in NativeGallery.class is:
    public static void OpenGallery(final Context context) {
    final Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("content://media/internal/images/media"));
    context.startActivity(intent);
    }

    then in NativeGallery.cs you can add to the previous method
    public static void OpenGallery()
    {
    #if !UNITY_EDITOR && UNITY_ANDROID
    AJC.CallStatic( "OpenGallery", Context );
    #elif !UNITY_EDITOR && UNITY_IOS
    _NativeGallery_OpenIosGallery();
    #endif
    }


    now you can call from script NativeGallery.OpenGallery();

    hope this helps :)
     
    JaffaJamGames likes this.
  41. meddmi

    meddmi

    Joined:
    May 11, 2017
    Posts:
    4
    In my case logcat contains next error message:
    UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/413458a143b5.png" is denied.

    But I'm sure that all permissions were granted, and also same build works on other device with Android version bellow 10.
    I have found an interest article Android 10’s Scoped Storage: Image Picker (Gallery/Camera) and a described method with using a requestLegacyExternalStorage with value true in the manifest file works for me. But according to same article this is not good solution and looks like it wouldn't work in the future.

    I guess it's would be great if @yasirkula have a chance to check this.
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    But I already did, on Oct 9, 2019. If your plugin is up-to-date, then I don't why it isn't working on your device. I couldn't test the update on an actual Android 10 device since I don't have one but it worked on an emulator. Having no further replies to this Issue, I think we can say that it works on some actual Android 10 devices, as well.

    P.S. Please try the latest releases available here and see if anything changes.
     
  43. meddmi

    meddmi

    Joined:
    May 11, 2017
    Posts:
    4
    Strange, I use the latest version from the asset store. Thanks for your reply, I'll try to investigate this a little bit more.
     
  44. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    185
    For some damn reason the getvideofromgallery isnt working anymore. I have no clue why, it was working before.

    I call this first..

    Code (CSharp):
    1. public void SelectVideoFromGallery()
    2.         {
    3.             NativeGallery.GetVideoFromGallery(OnVideoPicked);
    4.         }
    then this gets called..

    Code (CSharp):
    1.  public void OnVideoPicked(string _path)
    2.         {
    3.  
    4.             if (string.IsNullOrEmpty(_path))
    5.                 return;
    6.             _textureButt.SetActive(true);
    7.             _textbutt.SetActive(false);
    8.             FeedIndex = 2;
    9.             UploadFileToWhatEver(_path, true);
    10.            
    11.                
    12.         }
    this this gets called..

    Code (CSharp):
    1. public void UploadFileToWhatEver(string _url, bool _showPreview)
    2.         {
    3.             //AppManager.VIEW_CONTROLLER.ShowLoading();
    4.             StartCoroutine(GetFilrWhereEver(_url, true));
    5.         }
    and finally this..

    Code (CSharp):
    1.   private IEnumerator GetFilrWhereEver(string _url, bool _showPreview)
    2.         {
    3.             FeedType _type = GetFeedType();
    4.             Feed _feed = new Feed();
    5.             _feed.Type = _type;
    6.            
    7.            _feed.OwnerID = AppManager.USER_PROFILE.FIREBASE_USER.UserId;
    8.            _feed.ToUserID = feedDadaLoader.GetUserID();
    9.            
    10.             byte[] imageBytes = null;
    11.             byte[] videoBytes = null;
    12.             string fileName = System.Guid.NewGuid().ToString();
    13.             Texture2D previewTexure = new Texture2D(2, 2);
    14.  
    15.  
    16.  
    17.  
    18.             if (_type == FeedType.Image || _type == FeedType.Video) /// this checks if its a video or image
    19.             {
    20.                
    21.                
    22.              
    23.                 byte[] fileBytes = System.IO.File.ReadAllBytes(_url);
    24.  
    25.                 if (_type == FeedType.Video) // if its a video..
    26.                 {
    27.  
    28.                     Debug.Log("First Video");
    29.                     if (!CheckVideoSize(fileBytes))
    30.                     {
    31.                         Debug.Log("checing size");
    32.                         AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.MaxVideoSize);
    33.                         yield break;
    34.                     }
    35.                     PreviewPlayer.url = "file://" + _url;
    36.  
    37.                     videoBytes = fileBytes;
    38.                     while (PreviewPlayer.frame < 2)
    39.                     {
    40.                         Debug.Log("player frame is < 2");
    41.                         yield return null;
    42.                     }
    43.                     Texture2D _texture = ReadExternalTexture(PreviewPlayer.texture);
    44.  
    45.  
    46.                     ResizeTexture(_texture);
    47.  
    48.                     imageBytes = _texture.EncodeToJPG(AppManager.APP_SETTINGS.UploadImageQuality);
    49.                     _feed.MediaWidth = _texture.width;
    50.                     _feed.MeidaHeight = _texture.height;
    51.                     _feed.VideoFileName = fileName;
    52.  
    53.                     previewTexure = _texture;
    54.  
    55.                 }
    56.  
    57.                 if (_type == FeedType.Image)
    58.                 {
    59.                     Texture2D _texture = NativeCamera.LoadImageAtPath(_url, 1024, false, true, true);
    60.  
    61.  
    62.  
    63.                     yield return new WaitForEndOfFrame();
    64.  
    65.  
    66.  
    67.  
    68.  
    69.                     imageBytes = _texture.EncodeToJPG(AppManager.APP_SETTINGS.UploadImageQuality);
    70.                     _feed.MediaWidth = _texture.width;
    71.                     _feed.MeidaHeight = _texture.height;
    72.  
    73.                     previewTexure = _texture;
    74.                 }
    75.  
    76.             }
    77.  
    78.             if (_type == FeedType.Image || _type == FeedType.Video)
    79.             {
    80.                 if (_showPreview) // if we wanna show a preview, which we always do!..
    81.                 {
    82.                     AppManager.VIEW_CONTROLLER.HideLoading();
    83.                     if (_type == FeedType.Image) // images get called no problem..
    84.                     {
    85.  
    86.                         _closePicButt.SetActive(true);
    87.                         FeedPreviewRequest _previreRequest = new FeedPreviewRequest();
    88.  
    89.  
    90.                         _imageImage.texture = previewTexure;
    91.  
    92.                         float _bodyWidth = 800;
    93.                         float _imageWidth = _imageImage.texture.width;
    94.                         float _imageHeight = _imageImage.texture.height;
    95.                         float _ratio = _imageWidth / _imageHeight;
    96.                         float _expectedHeight = _imageHeight * _bodyWidth / _imageWidth;
    97.  
    98.                         _imageImage.rectTransform.sizeDelta = new Vector2(_bodyWidth, _expectedHeight);
    99.                         _posterHolder.sizeDelta = _imageImage.rectTransform.sizeDelta;
    100.  
    101.  
    102.  
    103.                         //AppManager.VIEW_CONTROLLER.FDU = gameObject.GetComponent<FeedDadaUoloader>();
    104.                         AppManager.VIEW_CONTROLLER.GetReq(_previreRequest);
    105.  
    106.  
    107.                         while (!_previreRequest.IsComplete)
    108.                         {
    109.                             yield return null;
    110.                         }
    111.                         if (!_previreRequest.IsSuccess)
    112.                         {
    113.                             yield break;
    114.                         }
    115.                         _feed.BodyTXT = _previreRequest.BodyText;
    116.                     }
    117.                     else if (_type == FeedType.Video) // this is not getting called!
    118.                     {
    119.                         _closePicButt.SetActive(true);
    120.                         FeedPreviewRequest _previreRequest = new FeedPreviewRequest();
    121.  
    122.  
    123.                         _videoImage.texture = previewTexure;
    124.  
    125.                         float _bodyWidth = 800;
    126.                         float _imageWidth = _videoImage.texture.width;
    127.                         float _imageHeight = _videoImage.texture.height;
    128.                         float _ratio = _imageWidth / _imageHeight;
    129.                         float _expectedHeight = _imageHeight * _bodyWidth / _imageWidth;
    130.  
    131.                         _videoImage.rectTransform.sizeDelta = new Vector2(_bodyWidth, _expectedHeight);
    132.                         _posterHolder.sizeDelta = _videoImage.rectTransform.sizeDelta;
    133.                         OnLoadVideo(previewTexure);
    134.                         ShowPlayBtn();
    135.  
    136.  
    137.                         //AppManager.VIEW_CONTROLLER.FDU = gameObject.GetComponent<FeedDadaUoloader>();
    138.                         AppManager.VIEW_CONTROLLER.GetReq(_previreRequest);
    139.  
    140.  
    141.                         while (!_previreRequest.IsComplete)
    142.                         {
    143.                             yield return null;
    144.                         }
    145.                         if (!_previreRequest.IsSuccess)
    146.                         {
    147.                             yield break;
    148.                         }
    149.                         _feed.BodyTXT = _previreRequest.BodyText;
    150.  
    151.                     }
    152.  
    153.  
    154.                 }
    155.             }
    156.             else
    157.             {
    158.                 _feed.BodyTXT = BodyTextInput.text;
    159.             }
    160.  
    161.             AppManager.VIEW_CONTROLLER.ShowLoading();
    162.  
    163.             // wait for preview callback
    164.             if (_type == FeedType.Image)
    165.             {
    166.              
    167.              
    168.                 FileUploadRequset _imageUploadRequest = new FileUploadRequset();
    169.                 _imageUploadRequest.FeedType = _type;
    170.                 _imageUploadRequest.FileName = fileName + "." + GetFileExtension(_url);
    171.                 _imageUploadRequest.UploadBytes = imageBytes;
    172.  
    173.                 FileUploadCallback _callBack = new FileUploadCallback();
    174.                 AppManager.FIREBASE_CONTROLLER.UploadFile(_imageUploadRequest, callback =>
    175.                 {
    176.                     _callBack = callback;
    177.                 }
    178.                 );
    179.                 while (!_callBack.IsComplete)
    180.                 {
    181.                     Debug.Log("Callback not complete image");
    182.                     yield return null;
    183.                 }
    184.                 if (!_callBack.IsSuccess)
    185.                 {
    186.                     Debug.Log("Callback not success image");
    187.                     AppManager.VIEW_CONTROLLER.HideLoading();
    188.                     AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.FailedUploadFeed);
    189.                     yield break;
    190.                 }
    191.              
    192.                 _feed.ImageURL = _callBack.DownloadUrl;
    193.             }
    194.             if (_type == FeedType.Video)
    195.             {
    196.                 _infoPanel.SetActive(false);
    197.                 Debug.Log("is video");
    198.                 // upload video
    199.                 FileUploadRequset _videoUploadRequest = new FileUploadRequset();
    200.                 _videoUploadRequest.FeedType = _type;
    201.                 _videoUploadRequest.FileName = fileName + "." + GetFileExtension(_url);
    202.                 _videoUploadRequest.UploadBytes = videoBytes;
    203.  
    204.                 FileUploadCallback _callBack = new FileUploadCallback();
    205.                 AppManager.FIREBASE_CONTROLLER.UploadFile(_videoUploadRequest, callback =>
    206.                 {
    207.                     Debug.Log("upload file");
    208.                     _callBack = callback;
    209.                 }
    210.                 );
    211.                 while (!_callBack.IsComplete)
    212.                 {
    213.                     Debug.Log("Callback not complete video");
    214.                     yield return null;
    215.                 }
    216.                 if (!_callBack.IsSuccess)
    217.                 {
    218.                     Debug.Log("Callback not success video");
    219.                     AppManager.VIEW_CONTROLLER.HideLoading();
    220.                     AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.FailedUploadFeed);
    221.                     yield break;
    222.                 }
    223.                 // upload video preview
    224.                 FileUploadRequset _imageUploadRequest = new FileUploadRequset();
    225.                 _imageUploadRequest.FeedType = FeedType.Image;
    226.                 _imageUploadRequest.FileName = System.Guid.NewGuid() + ".jpg";
    227.                 _imageUploadRequest.UploadBytes = imageBytes;
    228.  
    229.                 FileUploadCallback _callBack2 = new FileUploadCallback();
    230.                 AppManager.FIREBASE_CONTROLLER.UploadFile(_imageUploadRequest, callback =>
    231.                 {
    232.                     _callBack2 = callback;
    233.                 }
    234.                 );
    235.                 while (!_callBack2.IsComplete)
    236.                 {
    237.                     yield return null;
    238.                 }
    239.                 if (!_callBack2.IsSuccess)
    240.                 {
    241.                     AppManager.VIEW_CONTROLLER.HideLoading();
    242.                     AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.FailedUploadFeed);
    243.                     yield break;
    244.                 }
    245.  
    246.                 //_feed.VideoURL = _callBack.DownloadUrl;
    247.                 _feed.ImageURL = _callBack2.DownloadUrl;
    248.             }
    249.  
    250.             _feed.DateCreated = GetDate();
    251.             FeedUploadCallback _feedCallback = null;
    252.             if (_dropDown.options[_dropDown.value].text == "All Feeds")
    253.             {
    254.                 Debug.Log("Post is All");
    255.                 AppManager.FIREBASE_CONTROLLER.AddNewAllPost(_feed, callback =>
    256.                 {
    257.                     _feedCallback = callback;
    258.                 });
    259.              
    260.  
    261.             }
    262.             else if (_dropDown.options[_dropDown.value].text == "World Feed")
    263.             {
    264.                 Debug.Log("Post is World");
    265.                 AppManager.FIREBASE_CONTROLLER.AddNewWorldPost(_feed, callback =>
    266.                 {
    267.                     _feedCallback = callback;
    268.                 });
    269.              
    270.             }
    271.             else if (_dropDown.options[_dropDown.value].text == "Squad Feed")
    272.             {
    273.                 Debug.Log("Post is Friemds");
    274.                 AppManager.FIREBASE_CONTROLLER.AddNewFriendPost(_feed, callback =>
    275.                 {
    276.                     _feedCallback = callback;
    277.                 });
    278.  
    279.                
    280.                     AppManager.FIREBASE_CONTROLLER.SharePostWithFriends(AppManager.USER_PROFILE.FIREBASE_USER.UserId, _feed.Key);
    281.                
    282.             }
    283.            
    284.             while (_feedCallback == null)
    285.             {
    286.                 Debug.Log("callback request null");
    287.                 yield return null;
    288.             }
    289.             if (!_feedCallback.IsSuccess)
    290.             {
    291.                 AppManager.VIEW_CONTROLLER.HideLoading();
    292.                 AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.FailedUploadFeed);
    293.                 yield break;
    294.             }
    295.             if (_type == FeedType.Video)
    296.             {
    297.                 Debug.Log("uploaded to allpostkeys");
    298.                 string databasePath = AppSettings.AllPostsKey + "/" + _feed.Key + "/VideoURL";
    299.                 AppManager.Instance.Firebase.UploadAndCompressVideo(AppSettings.FeedUploadVideoPath + fileName + "." + GetFileExtension(_url), databasePath);
    300.             }
    301.             BodyTextInput.text = string.Empty;
    302.             // upload finish
    303.             AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.SuccessPost);
    304.             AppManager.VIEW_CONTROLLER.HidePoster();
    305.             AppManager.VIEW_CONTROLLER.HideLoading();
    306.  
    307.             feedDadaLoader.ResetLoader();
    308.             Debug.Log("finished");
    309.            
    310.             yield return new WaitForSeconds(1.5f);
    311.          
    312.  
    313.  
    314.         }

    Images work just fine. Ive tried diff things to see whats not calling and for somereason the video isnt returning a path. Images upload and show in my preview window just fine. Is there something new in the newest update that im missing??
     
  45. jmyoo555

    jmyoo555

    Joined:
    Jan 20, 2020
    Posts:
    1
    Hello @yasirkula, thank you for your great asset!
    I want to record video of the mobile screen (Android/ iOS )
    but I I don't know how to use the function 'NativeGallery.SaveVideoToGallery()'.
    Please help me..
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    @gaglabs Sorry to hear that. I don't know when the last time you've updated the plugin was so I can't tell what has changed since then. But full changelog and diffs are available at: https://github.com/yasirkula/UnityNativeGallery/commits/master. You can also revert to older versions until the issue is fixed: https://github.com/yasirkula/UnityNativeGallery/releases. Do you vaguely remember the previous version of your plugin? On which devices and OS versions did the new version fail?

    @jmyoo555 This plugin can't record the screen, you have to use a dedicated plugin for that. Please see this answer for two alternatives: https://forum.unity.com/threads/native-camera-for-android-ios-open-source.529560/#post-3681658
     
  47. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    185
    I recently updated to your new version. It was working back in Dec the last time i talked to you on the native cam forum. I updated unity twice since then and decided to test it because we are about to release our app. The gallery pops up just fine and im able to pick a video, but after that it hangs on loading and the video is never sent to the raw image as a placholder for preview.
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    On which devices and OS versions did the new version fail? Was the old version still working after updating Unity twice? Are there any meaningful error messages in Xcode console/logcat?
     
  49. jairoandrety

    jairoandrety

    Joined:
    Feb 24, 2016
    Posts:
    6
    Hello, I am testing your plugin and I am uploading photos from my phone, if I upload a photo it changes my name to pickImg and if I upload several the first photo will be called pickImg.
    is there any way to change that?
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Try calling this function in Awake/Start:
    Code (CSharp):
    1. using( var ajc = new AndroidJavaClass( "com.yasirkula.unity.NativeGalleryMediaPickerFragment" ) )
    2.     ajc.SetStatic<bool>( "tryPreserveFilenames", true );