admin管理员组

文章数量:1406921

I used simpl.info code as example. On their example I can see "TOSHIBA Web Camera - HD (13d3:5606)" in the "Video source" Select. Hence they can retrieve the label property of the sources. I can get the sources easily but the label is empty:

SourceInfo {facing: "", label: "", kind: "video", id: "0c2c5a2bf359a3ced6d7d39efe2f40477f50d5627df618a6f1998b5142437b27"}

Here is my code:

$(document).ready(function ()
{
    if (navigator.getUserMedia)
    {
        if (typeof MediaStreamTrack.getSources !== 'undefined')
        {
            MediaStreamTrack.getSources(gotSources);
        }
    }
});

function gotSources(sourceInfos)
{
    for (var i = 0; i < sourceInfos.length; i++)
    {
        var sourceInfo = sourceInfos[i];

        if (sourceInfo.kind == 'video')
        {
            console.log(sourceInfo);
        }
    }
}

I used simpl.info code as example. On their example I can see "TOSHIBA Web Camera - HD (13d3:5606)" in the "Video source" Select. Hence they can retrieve the label property of the sources. I can get the sources easily but the label is empty:

SourceInfo {facing: "", label: "", kind: "video", id: "0c2c5a2bf359a3ced6d7d39efe2f40477f50d5627df618a6f1998b5142437b27"}

Here is my code:

$(document).ready(function ()
{
    if (navigator.getUserMedia)
    {
        if (typeof MediaStreamTrack.getSources !== 'undefined')
        {
            MediaStreamTrack.getSources(gotSources);
        }
    }
});

function gotSources(sourceInfos)
{
    for (var i = 0; i < sourceInfos.length; i++)
    {
        var sourceInfo = sourceInfos[i];

        if (sourceInfo.kind == 'video')
        {
            console.log(sourceInfo);
        }
    }
}
Share Improve this question edited Dec 17, 2014 at 11:21 Arthur Rey asked Dec 10, 2014 at 18:44 Arthur ReyArthur Rey 3,0443 gold badges24 silver badges49 bronze badges 1
  • I bump into this too. In the documentation it is stated the label is empty if the user has not approved permissions to use his/hers camera / microphone, but for me the problem persist even if I have permissions. Can you try querying for the sources after you've been granted permission? – Lawliet Commented Dec 17, 2014 at 11:03
Add a ment  | 

1 Answer 1

Reset to default 5

As stated in answer #4, the user must have already granted permission to the page to use the media devices in order to get the label populated. When served over HTTPS, the browser will remember permission granted on subsequent loads, so the permission will have been granted before requesting media. When using HTTP, not HTTPS, the getUserMedia request must be made and accepted before MediaStreamTrack.getSources will populate labels.

I tried simpl.info on another puter and as expected the label was empty the first time, and populated after the second time.

本文标签: javascriptChrome MediaStreamTrackgetSources() returns sources with empty labelStack Overflow