提问者:小点点

无法在react中显示网络摄像机流


我试图显示我的网络摄像头流,但它只显示空白部分。

我的环境是ubuntu 18-06,Python-3.6。 这是我尝试的(我怀疑问题可能是由于src线(但我仍然不知道)。

import React from 'react';
import styled from 'styled-components'

const VideoFeed = () => {
    const VideoFeedSection = styled.section`
        display: flex;
        flex-direction: column;
        margin: 40px 10px;
        background-color: #ffffff;
        padding: 20px;
        width: 45vw;
        h2 {
            margin-top : 0;
            font-size: 45px;
            line-height: 1;
            font-weight: normal;
            color: #013087;
            text-align: center;
        }
`
    return (
            <VideoFeedSection className='some-space'>
                <h2>Video Feed - classroom 1</h2>
                <iframe allowFullScreen
                        title = 'camera feed'

            // !!! TO CHANGE !!!
                        src="//:0"
                        frameBorder="0"
                        width="100%"
                        height="576" />
            </VideoFeedSection>
    );
};

export default VideoFeed;

这是chrome控制台的错误

Warning: Received `true` for a non-boolean attribute `webkitallowfullscreen`.

If you want to write it to the DOM, pass a string instead: webkitallowfullscreen="true" or webkitallowfullscreen={value.toString()}.
    in iframe (at VideoFeed.jsx:24)
    in section (created by Context.Consumer)
    in StyledComponent (created by styled.section)
    in styled.section (at VideoFeed.jsx:22)
    in VideoFeed (at App.js:31)
    in main (created by Context.Consumer)
    in StyledComponent (created by [styled.main)]
    in styled.main (at App.js:30)
    in App (at src/index.js:7) index.js:1375

共2个答案

匿名用户

像这样试试。

<iframe allowFullScreen="true"
    title='camera feed'

    // !!! TO CHANGE !!!
    src="//:0"
    frameBorder="0"
    width="100%"
    height="576" />

或者你可以这样做

<iframe src="your_page_url"
    allowfullscreen="allowfullscreen"
    mozallowfullscreen="mozallowfullscreen"
    msallowfullscreen="msallowfullscreen"
    oallowfullscreen="oallowfullscreen"
    webkitallowfullscreen="webkitallowfullscreen"> </iframe> 

匿名用户

您在控制台中看到的警告是因为allowFullScreen不支持布尔值。

您可以通过添加设置“true”作为值来解决该警告。

    <iframe 
      allowFullScreen="true"
      webkitallowfullscreen="true"
      mozallowfullscreen="true"

见:https://github.com/facebook/react/issues/7848#issuecomment-334594775

然而,这并不是你看到一个空白屏幕的原因。 你加载到iframe中的源是什么?