Search Unity

NatShare - Free Sharing API

Discussion in 'Assets and Asset Store' started by Lanre, Apr 17, 2018.

  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666

    Hi all! I am pleased to announce an API we decided to make public, open, free: NatShare. With NatShare, you can share images and videos, save to the camera roll, and retrieve a thumbnail for a video. NatShare has been made an independent project from NatCorder, our video recording API for Unity Engine.

    NatShare Features Include:
    - Share images (Texture2D) using the native sharing UI
    - Share videos (using the video path) using the native sharing UI
    - Save images (Texture2D) to the camera roll
    - Save videos (using the video path) to the camera roll
    - Get a thumbnail for a video (using the video path)

    The API is free and is hosted on the Asset Store and GitHub. Please feel free to open issues for bugs and feature requests:

    NatShare on the Asset Store

    NatShare on GitHub

    Also, check out the release article.

    NatShare will be added to the Asset Store soon. Thank you!
     
    Last edited: May 17, 2018
    asa989 and dta-mobile-vn like this.
  2. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    250
    Hi. Coming back to my question about custom actions, the idea is to allow the player to choose what to do with a video. They can share on a social network, but might, on the other hand, to place it on the in game chat. We could make to share buttons in the game, but it feels much cleaner if we have a single share button, that shows the Native Share Sheet, but it includes, not only the supported share targets for that media type, but also some in game action, like for example share share in clan chat, or send to in game friend's inbox.

    Something like this:
    http://pinkstone.co.uk/how-share-objects-using-your-own-uiactivity/
    http://jayeshkawli.ghost.io/using-uiactivityviewcontroller-swift/
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    This use case is pretty specific to your application from the looks of it. This level of modification would have to be done by developers (you). You can fork the NatShare project and begin to modify it.
     
  4. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    250
    Will give it a go.
     
    Lanre likes this.
  5. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    42
    Does this api allow for posting to social media, such as Facebook, Twitter, Instagram? I think those are the main ones my boss wants. We'd like to be able to share images (taken with a different api) and video taken from NatCorder.

    It seems there are some pretty common device-native solutions for this that I wouldn't know where to begin to access. I presume they are device native because a lot of the Android apps and games seem to do these things in the exact same way.
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Yes it does. It is indeed a native solution, so it is similar to other apps that provide similar functionality.
     
    sinjimonkey likes this.
  7. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    42
    Thanks! I got that implemented so far (was easy - or at least it seemed easy.. I'm building the first test now.)

    Is there a way to be able to write the text of the post? I know a lot of games post messages to Facebook with things like coin requests or whatnot. We'd like to use it to be able to add event hashtags for our Augmented Reality campaigns.
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    That sounds good. Currently there isn't, but feel free to open a feature request issue on GitHub and we'll review it.
     
  9. gilkansolizaris

    gilkansolizaris

    Joined:
    Nov 18, 2016
    Posts:
    1
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    skyecast likes this.
  11. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Hi,

    Using natshare, I'm trying to get the thumbnail for the recorded video. Works perfect on Android, but iOS I get a weird result with the image becoming warped.

    This is the code I'm using:

    void OnReplay (string path) {

    NatShare.GetThumbnail(path, OnThumbnail);

    }

    void OnThumbnail (Texture2D thumbnail) {
    rawimage.texture = thumbnail;
    }


    Am I messing something up here?
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Can you share a screenshot? Also, what is the resolution of the returned thumbnail.
     
  13. Sacker3407

    Sacker3407

    Joined:
    Mar 6, 2013
    Posts:
    4
    Hi,

    I updated the NatCorder assets in my project and added the NatShare assets as well.

    I am getting this error: ".../NatShare-API-1.0/WebGL/NatShare.js(6,6): UCE0001: ';' expected. Insert a semicolon at the end."

    This semicolon error appears for all 9 lines with "const". Is there something I need to do for these imported assets to make this not appear as an error?

    Edit:
    I assume I downloaded the right asset pack from "https://github.com/olokobayusuf/NatShare-API". I just brought it into my project normally, but perhaps I am missing something?
     
    Last edited: May 4, 2018
  14. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Can you share a screenshot of the error? You aren't supposed to be receiving any error with the raw Javascript file (it shouldn't be compiled by anything). What version of Unity are you using? Did you move files around after importing?
     
  15. Sacker3407

    Sacker3407

    Joined:
    Mar 6, 2013
    Posts:
    4
    I am using Unity 2017.3.1.
    I imported the files into a specific sub-folder, but didn't move anything after it had been added to the project.

    Also, I reimported it and this error shows up in addition: "You are trying to import an asset which contains a global game manager. This is not allowed."
     

    Attached Files:

    Last edited: May 4, 2018
  16. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    It seems that you downloaded the entire GitHub project. You should download the unitypackage instead. When you import it, do not move it into a sub-folder as it may break Unity's plugin import schemes.
     
  17. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Attached screenshot. How do I check the resolution of the thumbnail? I haven’t set one manually.
     

    Attached Files:

  18. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    To get the size of the image, simply log the returned textured width and height. I have a pretty good idea what's going on. I'm working on a fix.

    EDIT: I have made a fix for this issue. Grab NatShare 1.0f2.
     
    Last edited: May 5, 2018
  19. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    For some reason now the app crashes on iOS as soon as recording is done. I'll test it today and see what's making it crash.
     
  20. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Can you share the logs and a screenshot of the call stack in Xcode? These should have a clue as to what's going on.
     
  21. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    I've attached the logs. Everything seems to be working fine until I try and use this code:

    Code (CSharp):
    1. void OnReplay (string path) {
    2.         Debug.Log("Saved recording to: "+path);
    3.     NatShare.GetThumbnail(path, OnThumbnail);
    4.  
    5.         }
    6.        
    7. void OnThumbnail (Texture2D thumbnail) {
    8.     //
    9.                         }
     

    Attached Files:

  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Can you share a screenshot of the Xcode screen when the crash happens? I need to see the call stack and what exactly is crashing.
     
  23. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Yep sure, what exactly should I be screenshotting? Bit of an xcode noob..
     

    Attached Files:

  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    I need to see the left pane which shows the call stack (below 'FPS').
     
  25. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Okay cool thanks. Did I need to screenshot any particular part of this / all of this? If so - is there easier way to export all of this?
     

    Attached Files:

  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    This is not it. I need to see the call stack for the earlier picture you shared (with the red line, not the green one). Immediately the crash happens, Xcode will show the red line and also show the call stack for the crashing thread. Immediately this happens, send me the screenshot. Don't navigate away.
     
  27. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Yep of course - sorry!
     

    Attached Files:

  28. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Perfect! I'm working on a fix now.
     
  29. twfarro

    twfarro

    Joined:
    Nov 23, 2013
    Posts:
    21
    This is a very cool plugin. I like the structure, which lends itself to being very extensible to other platform implementations.

    However, I noticed that the "message" field for sharing doesn't seem to do anything. So far I have only tested for android, so I am not sure if this is a known issue on iOS as well.
     
  30. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    I saw your comment on the GitHub issue. I'll track the issue there.
     
    twfarro likes this.
  31. twfarro

    twfarro

    Joined:
    Nov 23, 2013
    Posts:
    21
    Cool. Didn't mean to spam you, just wasnt sure where you'd prefer it to be written.
     
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    No worries. I prefer when you post to GitHub because I get a notification and it is more issue-oriented.
     
  33. developer_bigdipperstudio

    developer_bigdipperstudio

    Joined:
    Dec 31, 2014
    Posts:
    2
    Hi, I am a user of NatCam and NatCorder. I love your products and decided to use NatShare also in my project:).

    When I try to SaveToCameraRoll(Texture2D) in my android device I came to a situation that my phone seems trying to save the texture file ends with .png as a video file. I downloaded the source package of NatShare and found that there maybe typo in NatShare.java line from 76 to 78:

    values.put(MediaStore.Video.Media.TITLE, "Image");
    values.put(MediaStore.Video.Media.MIME_TYPE, "image/png");
    values.put(MediaStore.Video.Media.DATA, file.getAbsolutePath());

    Where I think "MediaStore.Video.Media" should be "MediaStore.Image.Media"?
     
    Lanre and twfarro like this.
  34. developer_bigdipperstudio

    developer_bigdipperstudio

    Joined:
    Dec 31, 2014
    Posts:
    2
    Sorry, "MediaStore.Images.Media" :(
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Good catch! I have changed it.
     
    twfarro likes this.
  36. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Awesome! Let me know when there’s a new version to test.
    thanks!
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    I've uploaded a fix. Grab NatShare 1.0f2 from the GitHub repo (release page).
     
  38. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    I've grabbed NatShare 1.0f2 and imported that into a blank Unity project with Natcorder and Vuforia imported. Using the "ReplayCam" scene example as a base, while I'm not getting a crash anymore when I try to grab the video thumbnail - I just get a black image. Also - the video that gets recorded now has pretty bad tearing (wasn't experiencing the tearing in the first version).
     
  39. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Can you send me the logs?
    We have fixed this issue and are adding one more fix to another issue before pushing it onto the Asset Store.
     
  40. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Here are the logs from xCode. On more tests its not always completely black. Sometimes the top of the image has part of the screenshot - like it has only loaded 10% and then failing.


    Awesome - is there an estimated date for this? (super keen to get this integrated into our AR app)
     
  41. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    I have created an issue on GitHub. Let's continue this conversation there. As far as NatCorder, I can't confidently give a release date estimate because Unity is taking an awfully long time to review packages we currently have pending.
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Also, what is the size of the video that you're getting the thumbnail from?
     
  43. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    Grabbed the dimensions of the thumbnail (using thumbnail.height/ thumbnail.width) and I get 1624 x 750 back.
     
    Lanre likes this.
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
  45. Arjun-Gupte

    Arjun-Gupte

    Joined:
    May 31, 2013
    Posts:
    21
    Not working for any ios device. Keeps on crashing whenever Natshare.share calls up.
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Can you share the logs from Xcode, or a screenshot of Xcode immediately the crash happens? What device and iOS version are you testing on?
     
  47. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Hey Mitch. I haven't been able to reproduce this issue on my end. Can you share the recorded video itself? Post it on the issue thread on GitHub.
     
  48. mitchtbh

    mitchtbh

    Joined:
    Dec 8, 2013
    Posts:
    65
    I've just realised the issue - I was applying the texture to a Raw Image that was disabled until called just after. Rookie mistake. Everything is working great now.

    How exactly do I take a screenshot as opposed to the video? I'd like to be able to click the replay button for a screenshot or hold it down for a video. I can see the sharing code for Natshare like: image.Share();

    What would be the best way to take a photo?
     
    Lanre likes this.
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,666
    Sounds good. You can use ScreenCapture.CaptureScreenshot to take a screenshot.
     
  50. fabiotgarcia

    fabiotgarcia

    Joined:
    Apr 28, 2017
    Posts:
    32
    Hi there!

    I used your plugin NatShare to share recorded videos.
    I was able to share successfully on Android however on IOS the native UI does not show up.. It does not work.
    I think maybe it cannot find the path to the video... are there any particular project settings for it?

    Best Regards
     

    Attached Files: