重新连接网络摄像头时,WebRTC会继续播放视频流 [英] WebRTC continue video stream when webcam is reconnected

查看:698
本文介绍了重新连接网络摄像头时,WebRTC会继续播放视频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 getUserMedia ,但我想处理webCam我正在流式传输的情况变得断线或不可用的情况。所以我在 stream 上找到 oninactive 事件传递给 successCallback 功能。此外,我想在插入完全相同的webcam / mediaDevice时重新启动视频流。

I've got simple video stream working via getUserMedia, but I would like to handle case when webCam what i'm streaming from becomes disconnected or unavailable. So I've found oninactive event on stream object passed to successCallback function. Also I would like to restart video stream when exactly same webcam/mediaDevice will be plugged in.

代码示例:

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

navigator.getUserMedia(constrains, function successCallback(stream) {
        this.video.src = URL.createObjectURL(stream);
        stream.oninactive = function (error) {
            //this handler runs when device becomes unavailable.
            this.onStreamInactive(error, stream);
        }.bind(this);
    }.bind(this), function errorCallback () {});

根据以上示例,我可以:

Based on the example above how i can:


  1. 检测最近连接的媒体设备

  2. 检查它与我从哪个设备流式传输


推荐答案

更好的方法是使用另外提到的 MediaDevices.ondevicechange()在这个帖子中回答,但它仍然落后于Chrome上的旗帜。而不是使用 ondechangechange()来枚举设备,在您开始呼叫时定期轮询 MediaDevices.enumerateDevices() ,在每个轮询间隔结束时,比较您在上一轮询中从设备获得的设备列表。通过这种方式,您可以了解在通话过程中添加/删除的新设备。

A better way would be to use MediaDevices.ondevicechange() as mentioned in the other answer in this thread, but it is still behind a flag on Chrome. Instead of using ondevicechange() to enumerate devices, poll MediaDevices.enumerateDevices() at regular interval when you start the call, at end of every poll interval compare the list of devices you get from the devices in the previous poll. This way you can know the new devices added/remove during the call.

这篇关于重新连接网络摄像头时,WebRTC会继续播放视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆