2017-06-16 292 views
0

我流ID从desktopCapture.chooseDesktopMedia API,但getUserMedia失败getUserMedia抛出错误NavigatorUserMediaError:InvalidStateError

navigator.mediaDevices.getUserMedia({ 
    audio: { 
     mandatory: { 
     chromeMediaSource: 'desktop', 
     chromeMediaSourceId: streamId 
     } 
    }, 
    video: { 
     mandatory: { 
     chromeMediaSource: 'desktop', 
     chromeMediaSourceId: streamId, 
     maxWidth: window.screen.width, 
     maxHeight: window.screen.height 
     } 
    } 
    }).then(function(stream) { 

    }).catch(function(err) { 
     // The error show here 
    console.log(err) 
    }); 

感谢

+0

对不起。我是编辑说明\t。错误显示在catch –

+0

你得到了什么错误。 – Kumar

+0

@Kumar响应于tabCapture.capture的错误:第一个参数是必需的。 运行时未经检查的runtime.lastError tabCapture.capture:尚未为当前页面调用扩展(请参阅activeTab权限)。 Chrome页面无法捕获。 –

回答

0

为,navigator.mediaDevices.getUserMedia返回你的承诺。所以,你必须像承诺一样使用它。你的功能应该是这样的。

var obj = { 
    audio: { 
     mandatory: { 
     chromeMediaSource: 'desktop', 
     chromeMediaSourceId: streamId 
     } 
    }, 
    video: { 
     mandatory: { 
     chromeMediaSource: 'desktop', 
     chromeMediaSourceId: streamId, 
     maxWidth: window.screen.width, 
     maxHeight: window.screen.height 
     } 
    } 
    }; 

window.navigator.mediaDevices.getUserMedia(obj).then(function(stream) { 
    // Do your work with the stream 
}).catch(function(err) { 
    // Your error show here. 
console.log(err) 
}); 

因为你可以看看这里的更多信息 - >Check it out希望它可以帮助

+0

错误显示在catch上。 –