仅一帧显示WebRTC流 [英] Only one frame displayed WebRTC stream

查看:254
本文介绍了仅一帧显示WebRTC流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PeerJS及其云托管服务器来构建WebRTC应用程序.这是我的代码:

I'm using PeerJS and their cloud-hosted servers to build a WebRTC application. Here's my code:

navigator.getMedia = ( navigator.getUserMedia ||
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia);

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

var callSettings = {
  video: {
    mandatory: {
      maxWidth: 400,
      maxHeight: 300
    }
  },
  audio: true
};

$(document).ready(function ()
{
    var videoel = $("#teacher-stream")[0];

    $(document).on('click', ".start-call", function () //A button initiates call
    {
        var peerID = $(this).data('id'); //Button contains ID of peer
        navigator.getMedia(callSettings, function (stream)
        {
            var call = peer.call(peerID, stream);
            call.on('stream', function(remoteStream)
            {
                console.log('stream!');
                videoel.src = window.URL.createObjectURL(remoteStream);
                            //On stream copy data to video el

            });
        });
    });

    peer.on('call', function(call)
    {
        console.log('got call');
        navigator.getMedia(callSettings, function(stream)
        {
            call.answer(stream);
            call.on('stream', function(remoteStream)
            {
                videoel.src = window.URL.createObjectURL(remoteStream);

            });
        });
    });

});

流启动,并且要求两个用户都授予网络摄像头访问权限.但是,除此之外,仅显示第一帧.尽管"Chrome"标签上的脉冲记录"图标仍会显示,但不会显示其他帧. 流!"上面的日志仅添加一次.

The stream initiates and both users are requested to give webcam access. However, past that only the very first frame is displayed. Though the pulsing record icon on the Chrome tab still displays, no further frames are shown. The "stream!" log above is only added once.

我曾尝试在本地托管服务器,以检查是否是问题所在,而事实并非如此.我想念什么?

I've tried hosting the server locally to check if that was the issue, and it wasn't. What am I missing?

推荐答案

我需要在视频元素中添加属性"autoplay = true".

I needed to add the attribute "autoplay = true" to my video element.

这篇关于仅一帧显示WebRTC流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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