Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Project Tiny and utilizing device camera and microphone

Discussion in 'Project Tiny' started by ovirta, Mar 10, 2020.

  1. ovirta

    ovirta

    Joined:
    Mar 20, 2015
    Posts:
    42
    As subject states we would be interested in creating browser apps for which Project Tiny would be a perfect choice. We also want to utilize device camera and microphone.

    Is this possible with Project Tiny?
    Any samples already doing this available?

    Thanks!
     
  2. yossi_horowitz_artie

    yossi_horowitz_artie

    Joined:
    Jan 30, 2019
    Posts:
    87
    We've made various modifications to Tiny's included JavaScript and C++ code to make microphone access possible. It was not a straightforward process. :)
     
  3. ovirta

    ovirta

    Joined:
    Mar 20, 2015
    Posts:
    42
    I can imagine :)

    There is some discussion on sharing data between js and c# here and here. These are for WebGL but procedure should be the same.
    - js side methods exported to LibraryManager mergeInto(LibraryManager.library).
    - c# class imports js side methods via [DllImport("__Internal")]

    Sharing microphone data is then possible via shared array:
    [DllImport("__Internal")]
    private static extern void InitJavaScriptSharedArray(float[] array, int length);

    Js side writes data to the array, which is then read on c# side.

    Just wondering if the same approach would work with device camera, where data would be shared from js to c# and written to eg rawimage or rawtexture?
     
  4. yossi_horowitz_artie

    yossi_horowitz_artie

    Joined:
    Jan 30, 2019
    Posts:
    87
    I don't see why it wouldn't! We'll find out at my company in a few months.
     
  5. ovirta

    ovirta

    Joined:
    Mar 20, 2015
    Posts:
    42
    I agree. MediaRecorder ondataavailable should make it straighforward to access video data on browser side and to send it to tiny side using blob object.