繁体   English   中英

带有 getUsermedia() 的前置摄像头错误错误:“Notreadableerror:无法启动视频源”

[英]Front camera error with getUsermedia() Error: “Notreadableerror: could not start video source”

在我的 html 代码中,我有 3 个视频标签,在桌面上视频可以正常工作,但是当我在移动设备上尝试时,只能使用前两个摄像头,当我在最后一个中指定“用户”摄像头时,会跳转到 android “Notreadableerror”中的下一个错误: 无法启动视频源”。

function enableCam() {

video = document.getElementById('video');
// Get access to the camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {

    var constraints;
    var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
    if (isMobile) {
        constraints = {video: {width: {
            exact: 256
        },
        height: {
            exact: 192
        }, facingMode: "user"}};

    }else {
       constraints = {video: {width: {
           exact: 256
       },
       height: {
           exact: 192
       }, facingMode: "environment"}};
    }

    navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {

        readFile(video,stream);//This method plays the video and save the image
    });
}
}

如果 getUserMedia 运行过多,则会在 iOS 13.3 上发生此错误。 13.4 修复了它。

此外,在再次运行 getUserMedia 之前停止以前的流可能会有所帮助。

即)由于您连续运行两次 getUserMedia,也许第一次捕获 stream,停止它,然后以 setTimeout 延迟运行第二个 getUserMedia 可能有助于解除阻塞。

约束也可能是一个问题:传递一个空约束“{}”可能会有所帮助。 传递“{audio:true,video:true}”可能也有帮助。

尝试不同的浏览器也可能会有所帮助; 铬,firefox,Safari,甚至歌剧。

我有一个使用智能手机摄像头的开源移动网络应用程序。 我不得不考虑不同浏览器、相机、手机和约束的许多特殊性。 如果您再次卡住,该代码可能会派上用场: https://github.com/steveseguin/obsninja

你给权限了吗?

config.xml

<platform name="ios">
 ...
 <custom-config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
   <string>Access to camera to make video calls.</string>
 </custom-config-file>
 <custom-config-file parent="NSMicrophoneUsageDescription" platform="ios" target="*-Info.plist">
   <string>Access to microphone to make calls.</string>
 </custom-config-file>
</platform>

Android 的以下内容:AndroidManifest.xml

<platform name="android">
 ...
 <custom-preference name="android-minSdkVersion" value="21" />
 <custom-preference name="android-targetSdkVersion" value="28" />
 <custom-config-file parent="/*" target="AndroidManifest.xml">
   <uses-permission android:name="android.webkit.PermissionRequest" />
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.RECORD_AUDIO" />
   <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
   <uses-permission android:name="android.permission.CAMERA" />
   <uses-feature android:name="android.hardware.camera" />
   <uses-feature android:name="android.hardware.camera.autofocus" />
 </custom-config-file>
</platform>

https://developers.connectycube.com/cordova/code-samples-videochat-cordova

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM