Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Webcam on Android not working?

Discussion in 'Android' started by phoberman, Feb 17, 2012.

  1. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    I've got live camera input working both on the desktop (MacBook Pro) and iOS (iPhone4), but I can't get anything out of either of my Android phones (LG Optimus and Samsung Galaxy Nexus).

    Here's my script (attach it to a plane with a RenderTexture)

    Code (csharp):
    1. #pragma strict
    2. private var devices : WebCamDevice[];
    3. public var deviceName : String;
    4. private var wct : WebCamTexture;
    5. private var resultString : String;
    6.  
    7.  
    8. function Start() {
    9.     yield Application.RequestUserAuthorization (UserAuthorization.WebCam | UserAuthorization.Microphone);
    10.  
    11.     if (Application.HasUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone)) {
    12.        devices = WebCamTexture.devices;
    13.        deviceName = devices[0].name;
    14.        wct = new WebCamTexture(deviceName, 640, 480, 30);
    15.        renderer.material.mainTexture = wct;
    16.        wct.Play();
    17.        resultString = "no problems";
    18.     } else {
    19.        resultString = "no permission!";
    20.     }
    21. }
    22.  
    23. function OnGUI() {
    24.     for (var i = 0; i < devices.length; i++) {
    25.        GUI.Box(Rect(100, 100+(i*25), 300, 25),devices[i].name);
    26.     }
    27.     GUI.Box(Rect(100, 100+(i*25), 400, 25),resultString);
    28. }
    29.  
    Would appreciate any advice or pointers.

    (also posted on Unity Answers http://answers.unity3d.com/questions/217940/)
     
  2. tonydongyiqi

    tonydongyiqi

    Joined:
    Feb 27, 2012
    Posts:
    1
    maybe you should do some setting in android manifest file. To require some authorization eh...
     
  3. mRadek

    mRadek

    Joined:
    Feb 17, 2009
    Posts:
    25
    So, is there a way to make it working on android?
     
  4. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    BUMP.

    Come on. Someone must have some ideas or advice. Or is no one working with cameras on Android?

    Here's my latest test script, and a jpg of the results.

    Code (csharp):
    1. #pragma strict
    2. private var devices : WebCamDevice[];
    3. private var deviceName : String;
    4. private var wct : WebCamTexture;
    5. private var resultString : String;
    6. private var update: boolean;
    7. private var data : Color32[];
    8.  
    9. function Start() {
    10.     yield Application.RequestUserAuthorization (UserAuthorization.WebCam | UserAuthorization.Microphone);
    11.     if (Application.HasUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone)) {
    12.        devices = WebCamTexture.devices;
    13.        deviceName = devices[0].name;
    14.        wct = new WebCamTexture(deviceName, 640, 360, 15);
    15.        renderer.material.mainTexture = wct;
    16.        wct.Play();
    17.        resultString = "no problems";
    18.     } else {
    19.        resultString = "no permission!";
    20.     }
    21.     data = new Color32[wct.width * wct.height];
    22. }
    23.  
    24. function Update() {
    25.     if (wct) {
    26.         if (wct.didUpdateThisFrame) {
    27.             update = true;
    28.             wct.GetPixels32 (data);
    29.         } else {
    30.             update = false;
    31.         }
    32.     }
    33. }
    34.  
    35. function OnGUI() {
    36.     for (var i = 0; i < devices.length; i++) {
    37.        GUI.Box(Rect(100, 100+(i*25), 200, 25),"NAME: "+devices[i].name);
    38.        GUI.Box(Rect(300, 100+(i*25), 200, 25),"FRONT FACING? "+devices[i].isFrontFacing);
    39.     }
    40.     GUI.Box(Rect(100, 100+(i*25), 200, 25),"OPENED? "+resultString);
    41.     GUI.Box(Rect(300, 100+(i*25), 200, 25),"PLAYING? "+wct.isPlaying);
    42.     GUI.Box(Rect(100, 125+(i*25), 200, 25),"UPDATED? "+update);
    43. }
     

    Attached Files:

  5. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    You completely ignored the only person who gave you advice, and it was good advice. Until you answer them, why would anyone suggest anything else?

    Did you update the manifest?
     
  6. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    OK, fair enough.

    I did look at the manifest and couldn't find anything wrong, but maybe I'm missing something.

    Here it is:

    Code (csharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="edu.usc.perrywct" android:versionName="1.0" android:versionCode="1">
    3.   <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    4.   <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    5.     <activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="reverseLandscape">
    6.       <intent-filter>
    7.         <action android:name="android.intent.action.MAIN" />
    8.         <category android:name="android.intent.category.LAUNCHER" />
    9.       </intent-filter>
    10.     </activity>
    11.     <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="reverseLandscape">
    12.     </activity>
    13.     <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="reverseLandscape">
    14.       <meta-data android:name="android.app.lib_name" android:value="unity" />
    15.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    16.     </activity>
    17.     <activity android:name="com.unity3d.player.VideoPlayer" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="reverseLandscape">
    18.     </activity>
    19.   </application>
    20.   <uses-feature android:glEsVersion="0x00020000" />
    21.   <uses-permission android:name="android.permission.INTERNET" />
    22.   <uses-permission android:name="android.permission.WAKE_LOCK" />
    23.   <uses-permission android:name="android.permission.CAMERA" />
    24.   <uses-feature android:name="android.hardware.camera" android:required="true" />
    25.   <uses-feature android:name="android.hardware.camera.front" android:required="true" />
    26.   <uses-sdk android:minSdkVersion="6" android:targetSdkVersion="15" />
    27. </manifest>
     
  7. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Have you tried using default values for width, height and refresh rate? Maybe the settings you're requesting aren't possible with the device.
     
  8. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    Unfortunately, I don't know how to query the phone to figure out what the default values are - specs on the phone are 1080p on the main camera, 720p on the front-facing one - I've tried those and every other standard resolution I can think of, but none of them make any difference

    In any case, according to the script reference, all I'm specifying are the requested width, height, fps:

    "The real width [height, frame rate] may be different, and will match the closest width [height, frame rate] supported by the device."

    So shouldn't it work whatever resolution I'm requesting?

    Meanwhile, does anyone have any suggestions regarding the AndroidManifest file? Does anything look wrong? I'd really love to get this working.
     
    Last edited: Mar 9, 2012
  9. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Well what I meant was not specifying a width/height/refresh rate. You can call the constructor without those things.

    Have you tried just doing a really stripped down test version? I can get the camera to work absolutely fine with:

    Start:
    Code (csharp):
    1.  
    2. m_CameraTexture = new WebCamTexture(WebCamTexture.devices[0].name);
    3.  
    4. if (m_CameraTexture != null)
    5. {
    6.       m_CameraTexture.Play();
    7. }
    8.  
    Update:
    Code (csharp):
    1.  
    2. if (m_CameraTexture != null  m_CameraTexture.didUpdateThisFrame)
    3. {
    4.        transform.renderer.material.mainTexture = m_CameraTexture;
    5. }
    6.  
     
  10. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    Didn't realize I could call constructor without those parameters, thanks.

    Tried it. Still nothing. Just like the more complicated version: when I run your stripped down version on the desktop or iPhone, it works fine.

    On Android (Samsung Galaxy Nexus), just a black plane.
     
  11. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    I don't have anything productive to offer, other than a "me too" - on an Asus Eee Transformer TF-101 (last year's version), it reports two cameras and everything looks fine except the picture is just black, whichever camera I use. I tried the same authorization request code that you're using, and confirmed via OnGUI that HasUserAuthorization is returning true.

    I have no idea where to find the manifest file, let alone what it ought to look like! As far as I can tell, Unity generates an APK and copies it straight to the device, and everything works except the camera.

    I found a lot of old threads, and UnityAnswers questions, on this topic but I think MADmarine's post is the first time I've seen anybody saying it actually works for them!
     
  12. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    I guess I should count myself lucky then...

    If it helps I'm running Android 3.1 on a Toshiba AT100 Tablet. Have you checked if there are any Android updates to your devices?
     
  13. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    George - The Android Manifest file is created when you build your application for Android - there's a Temp folder in the project folder, inside that a StagingArea folder gets created when you build, and inside that is the AndroidManifest.xml file. The manifest gets created on the fly every time you build your app, but as I understand it, you can move it to Assets/Plugins/Android/, make any changes you want to it, and then that's the manifest that will be loaded next time you build. Someone with more knowledge than me should confirm that I've got all the facts right on this.

    And (speaking of people with more knowledge than me) I would really appreciate it if someone - anyone - who understands these things could take a look at the Android Manifest file that I posted above and make some suggestions about what alterations or updates might have an effect.

    MADmarine - phones are up to date, don't think that's the problem

    tonydongyiqi? wccrawford? Anyone? Care to help us out here?
     
  14. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Someone just PM'ed me with a few more questions about how I got the camera to work on my tablet, I thought I'd just share some of my answers just in case it helps anyone else:

    I think it may be written somewhere that Android 4.0.3 is needed for the camera, but it is definitely not required for it to run on the tablet/phone. I do think you have to have the 4.0.3 SDK installed on your development system however. I'm not sure what the key bit of info is to getting the camera to work, so I'll just list as many things as I can about what I'm doing and hopefully you'll manage to get it working.

    I made sure that I downloaded the latest SDK for Android along with some others and pointed Unity at that. So have on my system the SDKs for 4.0.3, 2.3.3, and 2.1 installed. And that's WITH the Google APIs for each.

    In my Unity settings I put the minimum API Level as 2.3.3 Gingerbread (API level 10).

    The other settings are mostly at default (ARMv7 only, OpenGL ES 2.0, with auto install and internet access, write access to external storage).

    I don't know if this also makes a massive difference, but I don't start up my camera straight away. I find that if I try to do too much with the camera in a single frame my tablet crashes too. So perhaps try having a button in your app that will start up the camera (just for testing this out anyway), don't try to start up at the same time as the app.
     
  15. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    I've got all the Android SDKs installed, and the Google APIs as well.

    As far as "pointing Unity towards the SDK" - you just mean the setting in Preferences/External Tools/Android SDK Location, right? I have that set to /Developer/android-sdk-macosx

    I tried changing the minimum API level at 2.3.3 (and tried 4.0 also, since that's what's running on the phone).

    I tried using a button to start the camera up, instead of starting it up with the app.

    Still getting nothing but a big black rectangle.

    Anyway, MADmarine, I really appreciate all your help on this, whether we've solved it or not.

    Obviously I'm not the only one having this problem, but in the absence of anyone else chiming in with any ideas or suggestions (by now I would have expected somebody from Unity to offer some kind of support) I guess I will have to conclude that this is a bug, and that I should just file a bug report and give up until it gets fixed.

    Code (csharp):
    1. #pragma strict
    2.  
    3. private var m_CameraTexture : WebCamTexture;
    4.  
    5. function Start () {
    6. }
    7.  
    8. function Update () {
    9.     if (m_CameraTexture != null  m_CameraTexture.didUpdateThisFrame) {
    10.            transform.renderer.material.mainTexture = m_CameraTexture;
    11.     }
    12. }
    13.  
    14. function OnGUI() {
    15.     if (GUI.Button(Rect(50,10,200,50),"Start WebCam")) {
    16.         m_CameraTexture = new WebCamTexture(WebCamTexture.devices[0].name);
    17.         if (m_CameraTexture != null) {
    18.               m_CameraTexture.Play();
    19.         }
    20.     }
    21. }
     
  16. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Yep, sorry I wasn't too clear about that SDK part.

    It definitely shouldn't be this hard to get the camera working so there's a bug or two somewhere I agree. I guess another thing different from my setup is that I'm using C#, but this is just clutching at straws now.

    Hope you get it fixed soon.
     
  17. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    Hi MADmarine, thanks for giving more details. I wondered whether you could upload a working .apk file so we can test it on our devices? It would determine once and for all whether it's a device problem or a build problem.

    Thanks
     
  18. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I get the same black texture on my droid-X. Perhaps could you share your working android manifest?

    With DDMS I do see some errors.

    Code (csharp):
    1.  
    2. 04-06 00:56:45.116: D/CameraSettings(1223): defaultCapabilities: preview-size-values: 176x144,320x240,352x288,640x480,720x480,800x448,1280x720
    3. 04-06 00:56:45.116: D/CameraSettings(1223): defaultCapabilities: preview-frame-rate-values: 5,10,15,20,24,25,28,30
    4. 04-06 00:56:45.123: D/CameraSettings(1223): defaultCapabilities: picture-format-values: jpeg,jfif,exif
    5. 04-06 00:56:45.123: D/CameraSettings(1223): defaultCapabilities: picture-size-values: 640x480,1280x960,1600x1200,2048x1536,2592x1936,3264x1840,3264x2448
    6. 04-06 00:56:45.123: D/CameraSettings(1223): defaultCapabilities: jpeg-thumbnail-size-values: 0x0,160x90,160x120,176x144,320x180,320x240
    7. 04-06 00:56:06.373: E/OMXCodec(1223): Successfully allocated software codec 'VorbisDecoder'
    8. 04-06 00:55:31.645: E/CameraSettings(1223): Param type 50 not supported
    9. 04-06 00:56:06.389: W/CameraHal(1223): No overlay set before start preview
    10.  
    I'll try the thumbnail size to see if I get an image...

    It sucks that the API doesn't give access to the capabilities. Unless it does and I haven't seen that doc yet...
     
  19. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    This script works on my macbook pro, and on a toshiba thrive. No luck on droid-x. On the thrive, both cameras are detected.

    Code (csharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4.  
    5. public class CameraTest : MonoBehaviour
    6. {
    7.     /// <summary>
    8.     /// Meta reference to the camera
    9.     /// </summary>
    10.     public Material CameraMaterial = null;
    11.  
    12.     /// <summary>
    13.     /// The number of frames per second
    14.     /// </summary>
    15.     private int m_framesPerSecond = 0;
    16.  
    17.     /// <summary>
    18.     /// The current frame count
    19.     /// </summary>
    20.     private int m_frameCount = 0;
    21.  
    22.     /// <summary>
    23.     /// The frames timer
    24.     /// </summary>
    25.     private DateTime m_timerFrames = DateTime.MinValue;
    26.  
    27.     /// <summary>
    28.     /// The selected device index
    29.     /// </summary>
    30.     private int m_indexDevice = -1;
    31.  
    32.     /// <summary>
    33.     /// The web cam texture
    34.     /// </summary>
    35.     private WebCamTexture m_texture = null;
    36.  
    37.     // Use this for initialization
    38.     void Start()
    39.     {
    40.         if (null == CameraMaterial)
    41.         {
    42.             throw new ApplicationException("Missing camera material reference");
    43.         }
    44.  
    45.         Application.RequestUserAuthorization(UserAuthorization.WebCam);
    46.     }
    47.  
    48.     void OnGUI()
    49.     {
    50.         if (m_timerFrames < DateTime.Now)
    51.         {
    52.             m_framesPerSecond = m_frameCount;
    53.             m_frameCount = 0;
    54.             m_timerFrames = DateTime.Now + TimeSpan.FromSeconds(1);
    55.         }
    56.         ++m_frameCount;
    57.  
    58.         GUILayout.Label(string.Format("Frames per second: {0}", m_framesPerSecond));
    59.  
    60.         if (m_indexDevice >= 0
    61.             WebCamTexture.devices.Length > 0)
    62.         {
    63.             GUILayout.Label(string.Format("Selected Device: {0}", WebCamTexture.devices[m_indexDevice].name));
    64.         }
    65.  
    66.         if (Application.HasUserAuthorization(UserAuthorization.WebCam))
    67.         {
    68.             GUILayout.Label("Has WebCam Authorization");
    69.             if (null == WebCamTexture.devices)
    70.             {
    71.                 GUILayout.Label("Null web cam devices");
    72.             }
    73.             else
    74.             {
    75.                 GUILayout.Label(string.Format("{0} web cam devices", WebCamTexture.devices.Length));
    76.                 for (int index = 0; index < WebCamTexture.devices.Length; ++index)
    77.                 {
    78.                     var device = WebCamTexture.devices[index];
    79.                     if (string.IsNullOrEmpty(device.name))
    80.                     {
    81.                         GUILayout.Label("unnamed web cam device");
    82.                         continue;
    83.                     }
    84.  
    85.                     if (GUILayout.Button(string.Format("web cam device {0}{1}{2}",
    86.                                                        m_indexDevice == index
    87.                                                            ? "["
    88.                                                            : string.Empty,
    89.                                                        device.name,
    90.                                                        m_indexDevice == index ? "]" : string.Empty),
    91.                                          GUILayout.MinWidth(200),
    92.                                          GUILayout.MinHeight(50)))
    93.                     {
    94.                         m_indexDevice = index;
    95.  
    96.                         // stop playing
    97.                         if (null != m_texture)
    98.                         {
    99.                             if (m_texture.isPlaying)
    100.                             {
    101.                                 m_texture.Stop();
    102.                             }
    103.                         }
    104.  
    105.                         // destroy the old texture
    106.                         if (null != m_texture)
    107.                         {
    108.                             UnityEngine.Object.DestroyImmediate(m_texture, true);
    109.                         }
    110.  
    111.                         // use the device name
    112.                         m_texture = new WebCamTexture(device.name);
    113.  
    114.                         // start playing
    115.                         m_texture.Play();
    116.  
    117.                         // assign the texture
    118.                         CameraMaterial.mainTexture = m_texture;
    119.                     }
    120.                 }
    121.             }
    122.         }
    123.         else
    124.         {
    125.             GUILayout.Label("Pending WebCam Authorization...");
    126.         }
    127.     }
    128.  
    129.     // Update is called once per frame
    130.     private void Update()
    131.     {
    132.         if (null != m_texture
    133.             m_texture.didUpdateThisFrame)
    134.         {
    135.             CameraMaterial.mainTexture = m_texture;
    136.         }
    137.     }
    138. }
     
    Last edited: Apr 7, 2012
  20. enderwiggin2000

    enderwiggin2000

    Joined:
    Feb 21, 2011
    Posts:
    1
    I get the same issues as tgraupmann, and can't seem to find a solution either, other than looking elsewhere. Prime31s plugin works, but it launches an entirely seperate activity which isn't what we want.

    checking out the logcat, get interesting dump of camera stats, but nothing that hints at what maybe amiss, except the mysterious param 50, 51, and 53.


    Condensed log output:
    04-13 16:03:19.453: I/Unity(2365): Webcam permission = True
    04-13 16:03:19.476: I/Unity(2365): Webcame devices = 1
    04-13 16:03:19.508: I/Unity(2365): Cam back-facing device[0] = Camera 0
    04-13 16:03:19.508: D/Unity(2365): Create: m_DeviceName='Camera 0', device=0, w=0, h=0, fps=0
    04-13 16:03:19.508: I/Unity(2365): getNumCameras: 1
    04-13 16:03:19.508: I/Unity(2365): initCamera: 0
    04-13 16:03:19.812: D/CameraCompModule(1208): Focus distance (0) = 3.151, Infinity, Infinity
    04-13 16:03:19.828: D/Unity(2365): sz = 176x144
    04-13 16:03:19.828: D/Unity(2365): sz = 320x240
    04-13 16:03:19.828: D/Unity(2365): sz = 352x288
    04-13 16:03:19.828: D/Unity(2365): sz = 640x480
    04-13 16:03:19.828: D/Unity(2365): sz = 720x480
    04-13 16:03:19.828: D/Unity(2365): sz = 800x448
    04-13 16:03:19.828: D/Unity(2365): sz = 1280x720
    04-13 16:03:19.844: D/CameraSettings(1208): Extract changes completed, 0 total changes
    04-13 16:03:19.844: D/Unity(2365): cam[0]: size = 640x480; format=17, fps=(15000, 30000), bpp=12
    04-13 16:03:19.844: D/CameraCompModule(1208): Focus distance (0) = 3.151, Infinity, Infinity
    04-13 16:03:19.844: E/CameraSettings(1208): Param type 50 not supported
    04-13 16:03:19.844: D/CameraHal(1208): focus-distance = 3.151, Infinity, Infinity
    04-13 16:03:19.844: W/CameraHal(1208): No overlay set before start preview
     
  21. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    Upgraded Unity to 3.5.1f2 - just checked both my Android phones, no change, the problem persists.

    I have to say, the situation is really frustrating - this is some pretty basic essential missing functionality, and we're going on two months with no solution in sight and no response at all from our friends at Unity.
     
  22. rowenholt

    rowenholt

    Joined:
    Apr 17, 2012
    Posts:
    1
    I am having this problem with a galaxy W, the galaxy s 2 i tried is not having such an issue.
    scanning the logcat i found that there are a couple of lines which seem important:


    04-17 15:06:39.142: E/CAM_FD(1395): cam_conf open driver failed: Device or resource busy!
    04-17 15:06:39.142: E/CAM_FD(1395): cam_conf: CAMERA_EXIT

    So my question is this - is Unity3.5 somehow setting the camera to busy by default? I have altered the manifest to show either Camera permissions or not, and it has no effect.
     
  23. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Same thing with my galaxy nexus, I have a black texture.
    I tried also to use Qualcomm AR demos that uses cameras, I don't know if they use the webcameratexture but still not working. Everything is going well on my iPad.
    I hope they'll fix it very soon.
     
  24. headart

    headart

    Joined:
    May 1, 2012
    Posts:
    3
    Also having the black texture problem on the HTC One X running Android 4.0.3.

    Has anyone heard anything official about this from Unity support?
     
  25. phoberman

    phoberman

    Joined:
    Jan 16, 2008
    Posts:
    74
    Nope. Filed bug report but no response yet.

    Got my hands on a HTC Rezound - works fine.

    So here's the current score:

    WebCamTexture works on these phones
    Samsung Nexus S (v2.3.4)
    Sony Ericsson Xperia Play (v2.3.4)
    Sony Ericsson Xperia Mini (v2.3.4)
    Toshiba AT100 (v3.1)
    HTC Rezound (v2.3.4)
    Toshiba AT100 / Thrive (v3.1)
    Samsung Galaxy S2

    WebCamTexture doesn't work on these phones
    Samsung Galaxy Nexus (v 4.0.1)
    Samsung Galaxy W
    LG Optimus Thrill 4G (v2.3)
    Asus Eee Transformer TF-101
    Motorola Droid-x
    HTC One X (v4.0.3)
     
  26. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    Noticed this in the change log for 3.5.2:

    "Android: Fixed Webcam texture initialization problem on ICS device."

    Has this fixed the issue for anyone?
     
  27. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Doubtful. My DroidX is still on Gingerbread.
     
  28. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Interesting. I'll got my new testdevice in the beginning of the next week. Maybe someone else could test it with 3.5.2 and post it :)
     
  29. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Unfortunately, still doesn't work on my DroidX with Gingerbread.
     
  30. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    But wasn't the fix for 4.x?
     
  31. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    So not in 3.5.2 then. It was worth checking...
     
  32. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    No I ment Android 4.x :D
     
  33. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Today I got my Nexus S on 4.0.4 - the same error. Still black. That's more as bad, because my next App needs the Camera feature -.-

    Does anyone know if the Pime31-Cam-Plugins works?
     
  34. headart

    headart

    Joined:
    May 1, 2012
    Posts:
    3
    I just checked to see if Unity 3.5.2 had fixed this problem on my HTC One X (android 4.04) and it is still displaying a black texture.
     
  35. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    That's really bad -.- Hope there's a solution for this soon!!
     
  36. headart

    headart

    Joined:
    May 1, 2012
    Posts:
    3
    Just letting everyone know that i'm still not getting anything on the HTC One X. However, I have had some success on the HTC Desire S and the webcamTexture can be used as both a GUITexture or Object texture.

    Here is the code for for GUITexture

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [RequireComponent(typeof(GUITexture))]
    6. public class WebcamTexturePlain : MonoBehaviour
    7. {
    8.     // Texture to apply to the GUITexture we're attached to
    9.     private WebCamTexture webcamTexture;
    10.    
    11.     // Use this for initialization
    12.     void Start ()
    13.     {      
    14.         // Initialise and apply texture
    15.         webcamTexture = new WebCamTexture(WebCamTexture.devices[0].name);
    16.        
    17.         // Apply the texture
    18.         GUITexture guiTexture = this.GetComponent(typeof(GUITexture)) as GUITexture;
    19.         guiTexture.texture = webcamTexture;
    20.  
    21.         // Puts GUITexture in the center of the screen.
    22.         guiTexture.transform.position = new Vector3(0.5f,0.5f,0.5f);
    23.     }
    24.    
    25.     // Update is called once per frame
    26.     void Update ()
    27.     {
    28.         // Start the webcam texture if it's frozen
    29.         if (!webcamTexture.isPlaying) {
    30.             webcamTexture.Play();
    31.         }  
    32.     }
    33. }
    34.  
    Code for Object Texture

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class WebCamera : MonoBehaviour {
    6.  
    7.     private WebCamDevice[] devices;
    8.     private WebCamTexture webCam;  
    9.    
    10.     // Use this for initialization
    11.     void Start () {
    12.         devices = WebCamTexture.devices;
    13.         webCam = new WebCamTexture(WebCamTexture.devices[0].name);
    14.        
    15.         // Starts the webcam.
    16.         webCam.Play ();
    17.        
    18.         // Applies texture to object.
    19.         transform.renderer.material.mainTexture = webCam;
    20.     }
    21. }
    22.  
    I'll also be testing to see if the fault is also on the ASUS Transformer Pad 300 later tonight and I'll report back.

    UPDATE

    ASUS Transformer Pad 300 also displays the black screen.
     
    Last edited: Jun 3, 2012
    serve7a likes this.
  37. tsuchie

    tsuchie

    Joined:
    Jul 18, 2012
    Posts:
    1
    I met same issue on Galaxy Nexus and SHARP AQUOS PHONE 102SH yet, using Unity 3.5.2.
    No fixing issue, I cannot say that Android supported.
    I hope that hurry to fix this issues.
    but i have no ideas.

    Append comment :
    Seems Samsung Galaxy S3 also cannot work.
    My app decrease user rating stars on Google play, since this issues.:(

    I update score:

    WebCamTexture works on these phones
    Samsung Nexus S (v2.3.4)
    Samsung Galaxy S2
    Sony Ericsson Xperia Play (v2.3.4)
    Sony Ericsson Xperia Mini (v2.3.4)
    Toshiba AT100 (v3.1)
    Toshiba AT100 / Thrive (v3.1)
    HTC Rezound (v2.3.4)
    HTC Desire S
    NEC MEDIAS N-04C(v2.3.3)
    NEC MEDIAS N-04D(v2.3.3)

    WebCamTexture doesn't work on these phones
    Samsung Galaxy Nexus (v 4.0.1)
    Samsung Galaxy S3
    Samsung Galaxy W
    LG Optimus Thrill 4G (v2.3)
    Asus Eee Transformer TF-101
    Motorola Droid-x
    HTC One X (v4.0.3)
    SHARP AQUOS PHONE 102SH
    Nexus S (v4.0.4)
     
    Last edited: Jul 30, 2012
  38. Kirlim

    Kirlim

    Joined:
    Aug 6, 2012
    Posts:
    126
    Adding information:
    Webcam texture worked with somewhat low frame rates in a Samsung GP-1000L (android 2.3.3), and perfectly smooth in a Samsung Galaxy S YP-G70 (android 2.3.5).
     
  39. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Is there still now solution for the webcam texture problem on Android?
     
  40. JoshS

    JoshS

    Joined:
    Aug 21, 2012
    Posts:
    1
    Anybody found a solution to the webcam texture issue on Android?

    I'm thinking about using Vuforia and accessing the camera image from there as it seems to work well on all the phones I've tested on. Has anyone done this?
     
  41. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Cool idea and it's free :D But I've never test it. Is it hard to capture the camera-image trough Vuforia? Any code-sample?

    Are you sure that this works well via Unity on Android-devices?
     
  42. Kirlim

    Kirlim

    Joined:
    Aug 6, 2012
    Posts:
    126
    I have tested using Vuforia. Worked alright for both iPhone and Android (galaxy s). There is a simple trick that allow you to use vuforia camera as a texture explained in their manual. Drawback is that texture has a black area to keep its size quadratic, and even with UV mapping I failed to get rid of it. I did not find a way to change camera resolution, too.
     
  43. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Could you please post an example or give a link to this in the manual? I can't find it there -.-
     
  44. Maulik2208

    Maulik2208

    Joined:
    Oct 23, 2012
    Posts:
    3
    Is there any way to import photos from gallery to texture folder(means accessing gallery photos from app) and use the same image as a texture in unity 3d????