通过jQuery使用webRTC + canvas捕获图像

时间:2015-05-02 05:11:31

标签: jquery html5-canvas webrtc

当我执行此代码时,收到此错误消息:

$(document).ready(function () { window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; var Video = $('#CaptureImage'); var Canvas = $('#Canvas'); var Image = $('.Photo_BDD'); var Take = $('.Take'); var ImageContext = Canvas[0].getContext('2d'); var Width = Video.width() - 2; var Height = Video.height() - 2; Canvas.width = Width; Canvas.height = Height; var MediaSizeConstraints = { mandatory: { minWidth: Width, minHeight: Height, maxWidth: Width, maxHeight: Height } }; var LocalStream = null; var VideoConstraints = { audio: false, video: true, video: MediaSizeConstraints }; $('.Capture').click(function () { Start(); Take.click(function () { if (LocalStream) { ImageContext.drawImage(Video, 0, 0, Canvas.width, Canvas.height); Image.attr('src', Canvas.toDataURL('image/png')); } }); }); function Start() { try { navigator.getUserMedia(VideoConstraints, successCallback, errorCallback); } catch (e) { throw new Exception('Error:GetUserMedia not execute'); } } function Stop() { Video.trigger("pause"); Video.attr('Src', ''); LocalStream.stop(); } function successCallback(Stream) { LocalStream = Stream; if (window.URL) { Video.attr('Src', URL.createObjectURL(Stream)); } else { Video.attr('Src', Stream); } Video.attr('autoplay', true); } function errorCallback() { console.error('An error occurred: [CODE ' + error.code + ']'); } });

<projects>
    <project pid="p123">
        <leader>
            <name>Amanda</name>
        </leader>
        <analyst>
            <name>Bob</name>
        </analyst>
    </project>
    <project pid="p456">
        <leader>
            <name>John</name>
        </leader>   
    </project>
    <project pid="p789">
        <leader>
            <name>David</name>
        </leader>
        <analyst>
            <name>Amanda</name>
        </analyst>
    </project>
</projects>

0 个答案:

没有答案