Vue 調(diào)取本地視頻相關(guān)

目前已知問(wèn)題谷歌又問(wèn)題不能直接使用http調(diào)取,如果使用需要進(jìn)行一下配置
1 打開(kāi)谷歌瀏覽器,在地址欄輸入:
chrome://flags/#unsafely-treat-insecure-origin-as-secure
2 按回車(chē)鍵,配置如下信息。多個(gè)地址用逗號(hào)隔開(kāi)

image.png

如使用iframe嵌入聊天頁(yè)面,需原來(lái)需要增加 allow屬性
屬性值為: microphone;camera;midi;encrypted-media;

    <iframe allow="microphone;camera;midi;encrypted-media;"></iframe>

具體代碼

    var _this = this
    this.thisCancas =this.$refs.canvasCamera

    this.thisContext = this.thisCancas.getContext('2d')

    this.thisVideo = this.$refs.videoCamera

    // 舊版本瀏覽器可能根本不支持mediaDevices,我們首先設(shè)置一個(gè)空對(duì)象

    if (navigator.mediaDevices === undefined) {

      navigator.mediaDevices = {}

    }

    // 一些瀏覽器實(shí)現(xiàn)了部分mediaDevices,我們不能只分配一個(gè)對(duì)象

    // 使用getUserMedia,因?yàn)樗鼤?huì)覆蓋現(xiàn)有的屬性。

    // 這里,如果缺少getUserMedia屬性,就添加它。

    if (navigator.mediaDevices.getUserMedia === undefined) {

      navigator.mediaDevices.getUserMedia = function (constraints) {

        // 首先獲取現(xiàn)存的getUserMedia(如果存在)

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

        // 有些瀏覽器不支持,會(huì)返回錯(cuò)誤信息

        // 保持接口一致

        if (!getUserMedia) {

          return Promise.reject(new Error('此瀏覽器中未實(shí)現(xiàn)getUserMedia,不能調(diào)用攝像頭'))

        }

        // 否則,使用Promise將調(diào)用包裝到舊的navigator.getUserMedia

        return new Promise(function (resolve, reject) {

          getUserMedia.call(navigator, constraints, resolve, reject)

        })

      }

    }

    var constraints = {

      audio: false,

      video: {width: this.videoWidth, height: this.videoHeight, transform: 'scaleX(-1)'}

    }

    navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {

      // 舊的瀏覽器可能沒(méi)有srcObject

      if ('srcObject' in _this.thisVideo) {

        _this.thisVideo.srcObject = stream

      } else {

        // 避免在新的瀏覽器中使用它,因?yàn)樗诒粭売谩?
        _this.thisVideo.src = window.URL.createObjectURL(stream)

      }

      // _this.thisVideo.onloadedmetadata = function (e) {

      //   _this.thisVideo.play()

      // }

      _this.thisVideo.play()

    }).catch(err => {

      console.log(err)

    })
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過(guò)簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容