0

ReactPlayer.js cannot play the video streamed from an API. Please need some here

<video controls src='http://localhost:3001/api/video/my_video' /> // it works

<ReactPlayer url="http://localhost:3001/api/video/my_video"  controls/> // failed to work

enter image description here

The above is displayed using a <video>HTML elem.

enter image description here

Thats what is displayed when i use ReactPlayer

isaac
  • 19
  • 5

2 Answers2

0

This might work if you're facing CORS cross-origin restriction issue

<ReactPlayer
  url="http://localhost:3001/api/video/my_video"
  config={{
    file: {
      attributes: {
        crossOrigin: "true",
      }
    }
  }}
  controls
/>;


0

I had forgotten to config CORS on the server side.

const cors = require('cors');

app.use(cors()); // installing cors middleware so that any request can be accepted to get the resource i.e video streams. 

isaac
  • 19
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 20 '23 at 17:33
  • Can you explain how you configured CORS? – Nebulosar Jan 25 '23 at 10:41