Search Unity

Ios Safari Mobile Webcam Texture

Discussion in 'Web' started by Ploteus, Apr 14, 2019.

  1. Ploteus

    Ploteus

    Joined:
    Jun 29, 2015
    Posts:
    7
    I know it's not supported but i've tested camera texture on safari and it's just a black screen saying it doesn't have any camera but on any other browser it works I'm using unity 2018.0f2 there is no permission window what so ever , i think i'll try with getusermedia as a plugin and try to let unity know about camera, but in the meantime does anyone have any solution or maybe know in which unity it works?

    best regards
    tom
     
  2. Chromega1

    Chromega1

    Joined:
    Jan 8, 2014
    Posts:
    12
    I was able to get it working in development builds by modifying the <build>.wasm.framework.unityweb file in development builds.

    This might not be a 'production ready' fix (I'm disabling some error handling which should really be rewritten), but it's good enough for prototyping and should give you a head start! I did mine in Unity 2018.3.4 but hopefully this is similar enough to your version to be useful.

    Changes:
    -Search for
    enumerateMediaDevices
    . Comment out the
    if (!getMedia) return;
    line nearby.
    -Search for the
    _JS_WebCam_IsSupported
    function. Early out with a
    return true;

    -Search for the
    _JS_WebCamVideo_Start
    function. below the
    var video
    declaration, add these lines:
    Code (CSharp):
    1. video.setAttribute("playsinline", true);
    2. video.setAttribute("controls", true);
    3. setTimeout(() => {
    4.     video.removeAttribute("controls");
    5. });
    Then, replace the remainder of the function with:
    Code (CSharp):
    1.  navigator.mediaDevices.getUserMedia({
    2.   video: true,
    3.   audio: false
    4. }).then(function(stream) {
    5.   video.srcObject = stream;
    6.   webcam.canvas.appendChild(video);
    7.   video.play();
    8.   MediaDevices[deviceId].video = video;
    9.   MediaDevices[deviceId].stream = stream;
    10.   MediaDevices[deviceId].refCount++;
    11. }).catch(function(err) {
    12.   console.log("An error occurred! " + err);
    13. });
    That worked for me! Some of the other stuff about webcam access (like needing to be hosted on an https server) should still apply here. I hope these work for you, too!
     
    bugfinda and Ploteus like this.
  3. Ploteus

    Ploteus

    Joined:
    Jun 29, 2015
    Posts:
    7
    Chromega1 tried to write you but couldn't. So much virtual prize from me thank you so much for the help and sorry for such a late reply it fing works!!!!!!! :)
     
  4. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    This doesn't work for me. What Safari version are you using? The
    _JS_WebCamVideo_Start
    function doesn't run at all.
     
  5. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    We did recently get bug reports about this, I believe @Marks4 has been observing around this issue for a while as well. This is on our TODO list to fix, but unfortunately have not yet had time to sit down to the deep end of the details of this to recommend a fix/workaround.
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Notifying that this issue has been taken in implementation in our current development sprint.
     
  7. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953