I need to stream mp3 or mp4 from a node.js server and watch it on a html5 page. I am trying to use socket.io to sped up communications and i hope it will lower the latency that i have using simple http. I set up socket.io in my project, both on the client (mobile web application) and the server, but i can't figure out nor find on the web how to properly send data and lead it to a tag.
// Require HTTP module (to start server) and Socket.IO var http = require('http'); var io = require('socket.io'); var port = 8080; // Start the server at port 8080 var server = http. createServer(function(req, res){ // Send HTML headers and message res. writeHead(200,{ 'Content-Type': 'text/html' }); res.
In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .
Nodejs is very good to streaming audio and video, but nodejs is a new technology, so it's don't have a lot of softwares yet.
The bidirectional channel between the Socket.IO server (Node. js) and the Socket.IO client (browser, Node. js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.
Try ffmpeg to make sync audio/video streaming. In HTML5 audio and video tag automatically play it when you give source address of server in src element of audio/video tag.
please see socket.io-stream project https://www.npmjs.org/package/socket.io-stream
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With