打开客户端本地应用,获取摄像头(可切换)

HTML

<div id="bo">
    <div align="center" >
        <input type="hidden" name="imgValue" id="imgValue" />
        <button id="btnOpen1" class="btn btn-default" type="button" >
        <!-- href为注册表的值 -->
            <a href="aClient://" onclick="return luzhi()">录制视频</a></button>
        <span>选择摄像头:<select id="videoSource"></select></span>
    </div>

    <div id="vdoOne" align="center" style="width: 1300px;height: 750px;margin: 10px 17%">
        <video id="video" controls autoplay style="width: 100%; height:100%; object-fit: fill"></video>
    </div>
    <canvas id="canvasPreview" style="margin-top:15px;" width="1" height="1"></canvas>
    <canvas id="canvasUpload" style="display:none;" width='1' height='1'></canvas>
</div>

JS

 Elements for taking the snapshot
    var canvasPreview = document.getElementById('canvasPreview');
    var canvasUpload = document.getElementById('canvasUpload');
    var contextPreview = canvasPreview.getContext('2d');
    var contextUpload = canvasUpload.getContext('2d');
    var funId=$("#funId").val();
    $("#afunId").val(funId);
    //#################### Video Source #######################3
    var videoElement = document.querySelector('video');
    var videoSelect = document.querySelector('select#videoSource');
    navigator.mediaDevices.enumerateDevices()
            .then(gotDevices).then(getStream).catch(handleError);
    videoSelect.onchange = getStream;


    function gotDevices(deviceInfos) {
        for (var i = 0; i < deviceInfos.length; ++i) {
            var deviceInfo = deviceInfos[i];
            var option = document.createElement('option');
            option.value = deviceInfo.deviceId;
            if (deviceInfo.kind === 'videoinput') {
                option.text = deviceInfo.label ||
                        'camera ' +
                        (videoSelect.length + 1);
                videoSelect.appendChild(option);
            } else {
                console.log('Found ome other kind of source/device: ', deviceInfo);
            }
        }
    }
    var _streamCopy = null;
    function getStream() {
        if (_streamCopy != null) {
            try {
                _streamCopy.stop(); // if this method doesn't exist, the catch will be executed.
            } catch (e) {
                _streamCopy.getVideoTracks()[0].stop(); // then stop the first video track of the stream
            }
        }
        var constraints = {
            audio:false,
            video: {
                optional: [
                    {
                        sourceId: videoSelect.value
                    }
                ]
            }
        };
        navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(handleError);
    }
    function gotStream(stream) {
        _streamCopy = stream; // make stream available to console
        videoElement.srcObject = stream;
    }
    function handleError(error) {
        alert(error.name + ": " + error.message);
    }

结束

以上为获取摄像头,如果摄像头自带话筒,话筒跟随摄像头走

以下为html根据注册表打开本地文件

  • 待补充
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值