Java Android 模拟器:无法启动网络摄像头以在模拟器中捕获图片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27875415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:12:26  来源:igfitidea点击:

Android Emulator: Unable to start webcam to capture picture in emulator

javaandroidandroid-studioemulationavd

提问by Alessandro Roaro

I have created an armeabi API 21 emulator in the AVD manager in Android Studio, set it to use the webcam as a front camera, and launched it. The problem is that it's not able to open it, as I'm getting this error:

我在 Android Studio 的 AVD 管理器中创建了一个 armeabi API 21 模拟器,将其设置为使用网络摄像头作为前置摄像头,然后启动它。问题是它无法打开它,因为我收到此错误:

emulator: ERROR: camera_device_start_capturing: VIDIOC_STREAMON on camera '/dev/video0' has failed: Timer expired
emulator: ERROR: _camera_client_query_start: Cannot start camera '/dev/video0' for NV21[640x480]: Inappropriate ioctl for device

How can I solve this?

我该如何解决这个问题?

The webcam works normally using other software. The operative system is Ubuntu 14.04.

网络摄像头使用其他软件正常工作。操作系统为 Ubuntu 14.04。

回答by bonnyz

You can try to manually edit your AVD's configuration fileunder

你可以尝试手动编辑您的AVD的配置文件

~/.android/avd/yourAvdName/config.ini

~/.android/avd/yourAvdName/config.ini

by adding this line:

通过添加这一行:

hw.camera=yes

UPDATE

更新

You can try to specify the real resolutionof your webcam:

您可以尝试指定网络摄像头的真实分辨率

hw.camera.maxHorizontalPixels=XXX
hw.camera.maxVerticalPixels=XXX

Keep in mind that the default value for maxHorizontalPixelsis 640and for maxVerticalPixelsis 480, so chaning this values may help you to solve your issues.

请记住,默认值maxHorizo​​ntalPixels640maxVerticalPixels480,所以chaning这个值可以帮助你解决你的问题。

回答by Mayavi

To enable Camera in your Android Emulator, just add following highlighted code in your AVD's config.ini file. You can find the config.inifile under your <userdirectory>/.androidfolder.

要在 Android 模拟器中启用相机,只需在 AVD 的 config.ini 文件中添加以下突出显示的代码。您可以config.ini在您的<userdirectory>/.android文件夹下找到该文件。

File: ~/.android/config.ini

文件: ~/.android/config.ini

hw.lcd.density=160<br>
skin.name=HVGA<br>
skin.path=platforms\android-9\skins\HVGA<br>
hw.cpu.arch=arm<br>
abi.type=armeabi<br>
vm.heapSize=24<br>
image.sysdir.1=platforms\android-9\images\<br>
hw.camera=yes<br>
sdcard.size=64M<br>

In case you don't find the config.inifile or want to enable Camera support through Android SDK and AVD Manager do the following:

如果您找不到该config.ini文件或希望通过 Android SDK 和 AVD Manager 启用相机支持,请执行以下操作:

Open Android SDK and AVD Manager:

打开 Android SDK 和 AVD 管理器:

  1. Add SD Card in AVD
    In the SD Card setting, set the value for Size. To enable camera, the SD Card must be enabled in Emulator.
  2. Add Camera Support in Hardware under AVD
    Now under Hardware section, click New button to add Camera hardware. It will open following Dialog box. Select Camera support from the Property dropdown and click Ok.
  3. Enable Camera Support in Hardware
    The new hardware: Camera support is visible under Hardware section. Set its value to yes and save changes by pressing Edit AVD.
  4. Save the changes and launch the emulator.
  1. 在 AVD 中添加 SD 卡 在
    SD 卡设置中,设置大小的值。要启用相机,必须在模拟器中启用 SD 卡。
  2. 在 AVD
    下的硬件中添加相机支持现在在硬件部分下,单击新建按钮以添加相机硬件。它将打开以下对话框。从“属性”下拉列表中选择“相机支持”,然后单击“确定”。
  3. 在硬件中启用相机支持
    新硬件:在硬件部分下可以看到相机支持。将其值设置为 yes 并通过按 Edit AVD 保存更改。
  4. 保存更改并启动模拟器。

回答by BST Kaal

In Android Studio, go to AVD Manager, click on edit (pencil) button in Actions. After that, in next appearing window, click on Advance settings, and then scroll down and in Camera options, select webcam for front and back.

在 Android Studio 中,转到 AVD Manager,单击 Actions 中的编辑(铅笔)按钮。之后,在下一个出现的窗口中,单击高级设置,然后向下滚动并在相机选项中,选择前后网络摄像头。

回答by Erdal G.

I had a similar issue with a slightly different error message under OS X. I turned out that everything was ok but the emulator is crashing when the camera takes too much time to initialize.

我在 OS X 下遇到了类似的问题,错误消息略有不同。我发现一切正常,但是当相机需要太多时间来初始化时,模拟器崩溃了。

I my case I ended up closing other applications and it worked. You may want to test in a more performant computer.

我的情况我最终关闭了其他应用程序并且它起作用了。您可能希望在性能更高的计算机上进行测试。