Skip to content
Advertisement

MediaSource never emit sourceopen event in React

I’m trying to stream a video file using Javascript’s MediaSource API in a React custom hook.

Here’s the snippet of my code:

JavaScript
JavaScript

It looks like mediaSource never emit 'sourceopen' event.

What more, when I’m trying to use this code in different project with simple html and javascript it works fine.

I was trying to use document.getElementByTagName instead of useRef or use this directly in my component, but with the same result.

Can somebody tell me what is the problem? Is there any problem with React or something?

Advertisement

Answer

Instantiate and maintain state of MediaSource throughout the scope of the component:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement