question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support srcObject attribute for video element

See original GitHub issue

Do you want to request a feature or report a bug?

feature

What is the current behavior?

currently you cannot set the srcObject for a video. You get an error:

Warning: React does not recognize the `srcObject` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `srcobject` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template for React 16: https://jsfiddle.net/Luktwrdm/, template for React 15: https://jsfiddle.net/hmbg7e9w/).

return (
      <video srcObject={this.props.stream}>
)

There is another issue that was closed but the issue was never resolved: https://github.com/facebook/react/pull/1474

Firefox has deprecated using URL.createObjectURL() and Safari doesn’t support it.

What is the expected behavior?

The ability to set the srcObject on a video element. This is common for WebRTC applications now.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

“react”: “^16.0.0”

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:25
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

39reactions
tjmehtacommented, May 14, 2020

Just wrap the video element with a custom video component:

import { VideoHTMLAttributes, useEffect, useRef } from 'react'

type PropsType = VideoHTMLAttributes<HTMLVideoElement> & {
  srcObject: MediaStream
}

export default function Video({ srcObject, ...props }: PropsType) {
  const refVideo = useRef<HTMLVideoElement>(null)

  useEffect(() => {
    if (!refVideo.current) return
    refVideo.current.srcObject = srcObject
  }, [srcObject])

  return <video ref={refVideo} {...props} />
}
30reactions
gaearoncommented, Jan 6, 2018

Please see my reply in https://github.com/facebook/react/pull/9146#issuecomment-355584767 for why we’re not doing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTMLMediaElement.srcObject - Web APIs | MDN
The srcObject property of the HTMLMediaElement interface sets or returns the object which serves as the source of the media associated with ...
Read more >
How to add srcObject attribute of video tag and dynamically ...
How to add srcObject attribute of video tag and dynamically insert that to html page using java script,jQuery · 1 · [object%20MediaStream]:1 ...
Read more >
HTMLMediaElement.srcObject
The srcObject property of the HTMLMediaElement interface sets or returns ... a media source is assigned to a newly-created <video> element.
Read more >
Dealing with HTMLMediaElements and srcObjects in ...
In this case, using a single video element can then get into a state where audio is not played since a video frame...
Read more >
Binding to srcObject attribute - Get Help - Vue Forum
This is my first post on this forum :grinning: In my app, I get a video stream from the user's webcam and I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found