I\'m trying to play video from websocket
The fundamental problem here is you cannot stream those data coming out of MediaRecorder
and expect the other end to play it; it is not a complete video. It will only work if the receiving end is able to receive the initialization bytes--which I doubt that will work in a real-world scenario.
What you can do is to create an interval that will start/stop the MediaRecorder
for example every 1 second to make 1 second video chunks that you can transmit over the wire (best I know and tested is websockets)
I strongly suggest not to use MediaRecorder
is you are doing real-time video streaming which was not indicated in your post, but if yes, it would be better that you create a canvas to copy the stream and do some requestAnimationFrame
stuff that can capture your video stream into a something you can transmit.
Take a look at this demo for reference: https://github.com/cyberquarks/quarkus-websockets-streamer/blob/master/src/main/resources/META-INF/resources/index.html
MediaRecorder
in my experience response is delayed that would generally add quite a delay in the video, not to mention the delay that the socket would also introduce.
Generally, other developers would suggest that you just take the WebRTC route, however based on my experience also WebRTC is not generally faster.