【问题标题】:HTML5 getUserMedia is not streamingHTML5 getUserMedia 没有流式传输
【发布时间】:2015-03-25 13:30:51
【问题描述】:

我写了一个 navigator.getUserMedia() 脚本,但它不能正常工作。

我在另一个测试中重用了几乎相同的代码行,并且成功了。 问题是,实际上相机已打开(在获得许可后) 但流不是流式传输的。摄像头保持开启,但视频元素仅显示静态图像(可能是第一帧)。

视频元素的src是一个blob。

这是我的标记:

<video src="" id="camera-stream">
    <canvas style="display:none"></canvas>
</video>

基本脚本如下:

navigator.getUserMedia = navigator.getUserMedia || navigator.msGetUserMedia
                        || navigator.webkitGetUserMedia 
                        || navigator.mozGetUserMedia;

window.URL = window.URL || window.webkitURL;

var video, canvas, ctx, previewImg, localMediaStream = null;

function startCapture(){
    console.log("Start Capture invoked");
    if( !video || !navigator.getUserMedia || !window.URL ){
        console.log("Start capture returned.");
        return;
    }

    var args = {
        video: true
    };
    navigator.getUserMedia(args, captureSuccess, captureError);
}

function captureSuccess(stream){
    console.log("Capture successful");
    localMediaStream = stream;
    video.src = window.URL.createObjectURL(localMediaStream);  
    console.log("Stream: ", stream);
}

function captureError(e){
    console.log("Capture failed", e);
}

在 jQuery onClick-hander 中为链接调用 startCapture() 函数。

我的脚本有错误吗?

【问题讨论】:

    标签: javascript html html5-video getusermedia


    【解决方案1】:

    好的,我发现了错误。

    也许这会对某些人有所帮助。 我忘了为视频元素设置autoplay="autoplay" 属性。

    【讨论】:

    • 那是我的情况
    猜你喜欢
    • 1970-01-01
    • 2012-08-12
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2019-11-08
    • 1970-01-01
    相关资源
    最近更新 更多