How to stream audio / video with a socket (.io) from a node.js server to an html5 page

I need to transfer mp3 or mp4 from the node.js server and watch it on the html5 page. I am trying to use socket.io to speed up the connection, and I hope this will reduce the delay that I use simple http. I configured socket.io in my project, both on the client (mobile web application) and on the server, but I can’t understand and cannot find on the Internet how to send data correctly and put it in a tag.

+6
source share
3 answers
+4
source

Try ffmpeg to synchronize audio / video streams. In HTML5, an audio and video tag automatically plays it when you specify the source address in the src element of the audio / video tag.

+3
source

Check out this example:

var captureMe = function () { if (!videoStreamUrl) alert('error') context.translate(canvas.width, 0); context.scale(-1, 1); context.drawImage(video, 0, 0, video.width, video.height); var base64dataUrl = canvas.toDataURL('image/png'); context.setTransform(1, 0, 0, 1, 0, 0); var img = new Image(); img.src = base64dataUrl; window.document.body.appendChild(img); } button.addEventListener('click', captureMe); navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; window.URL.createObjectURL = window.URL.createObjectURL || window.URL.webkitCreateObjectURL || window.URL.mozCreateObjectURL || window.URL.msCreateObjectURL; navigator.getUserMedia({video: true}, function (stream) { allow.style.display = "none"; videoStreamUrl = window.URL.createObjectURL(stream); video.src = videoStreamUrl; }, function () { console.log('streaming error'); }); }; 

working example anonymous video chat test

source link http://html5.by/blog/html5-image-capture-getusermedia-stream-api-mirror/

0
source

Source: https://habr.com/ru/post/969735/


All Articles