Open daslicht opened 8 years ago
Yes it is possible
Server
io.on('connection', function (socket) {
socket.on('client-stream-request', function (data) {
var stream = ss.createStream();
var filename = __dirname + '/downloads/' + <YOURSONG.MP3>;
ss(socket).emit('audio-stream', stream, { name: filename });
fs.createReadStream(filename).pipe(stream);
});
});
Client
var audio = document.getElementById('player');
ss(socket).on('audio-stream', function(stream, data) {
parts = [];
stream.on('data', function(chunk){
parts.push(chunk);
});
stream.on('end', function () {
audio.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
audio.play();
});
});
AWESOME, i will try it soon ! <3 THANK YOU VERY MUCH!
Is it also possible to send additional data with it like Metadata and is it even possible to send it to a specific point of time ?
You can emit it as a separate event or include it in the data object that is sent with the stream
ss(socket).on('audio-stream', function(stream, data) {}
ok , but what about time sensitive data ? Lets say I like to push metadata once the Playback has reach 1Minute, 30 Seconds of the source ? Is at hat possible at all ?
Hi, Could you provide the full code?
With this html part its working:
<audio id="player" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Example over here :D https://github.com/zoutepopcorn/audio_socket/tree/master
is there a way to do it in real time?
There is a way to stream microphone in a real time, but I have small problem on my implementation..
Update: I just uploaded this library, but it still need some improvement https://github.com/ScarletsFiction/SFMediaStream
@StefansArya Can I use that library to stream binary blobs (sent as chunks of 3-seconds) ? Finding it very difficult to implement
Hmm, I think you could only send the buffer data (without media header). Because that's what I can get after calling mediaRecorder.requestData()
.
To stream chunks of 3 seconds you need to change the latency to 3000ms. I have an example on the repository that default to 100ms, maybe you can use that for experimenting.
And don't forget to set the similar latency to the streamer too.
Yes it is possible
Server
io.on('connection', function (socket) { socket.on('client-stream-request', function (data) { var stream = ss.createStream(); var filename = __dirname + '/downloads/' + <YOURSONG.MP3>; ss(socket).emit('audio-stream', stream, { name: filename }); fs.createReadStream(filename).pipe(stream); }); });
@duncanhoggan , is it a good idea use sockets to build a streaming server to work as a streaming service on demand?
that doesn't take bandwidth throttling into account no ? I just push as fast as possible no ?
Yes it is possible Server
io.on('connection', function (socket) { socket.on('client-stream-request', function (data) { var stream = ss.createStream(); var filename = __dirname + '/downloads/' + <YOURSONG.MP3>; ss(socket).emit('audio-stream', stream, { name: filename }); fs.createReadStream(filename).pipe(stream); }); });
@duncanhoggan , is it a good idea use sockets to build a streaming server to work as a streaming service on demand?
ss is not defined
Yes it is possible
Server
io.on('connection', function (socket) { socket.on('client-stream-request', function (data) { var stream = ss.createStream(); var filename = __dirname + '/downloads/' + <YOURSONG.MP3>; ss(socket).emit('audio-stream', stream, { name: filename }); fs.createReadStream(filename).pipe(stream); }); });
Client
var audio = document.getElementById('player'); ss(socket).on('audio-stream', function(stream, data) { parts = []; stream.on('data', function(chunk){ parts.push(chunk); }); stream.on('end', function () { audio.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts)); audio.play(); }); });
what is ss here ????
what is ss here ????
The solution @duncanhoggan provided is working. But what it do is it firstly read the whole file then after that it plays. But What I want is, I want to stream the file into chunks. There can be the delay for max 4-5 seconds.
Can anyone please provide the solution for this?
@rajatlnweb if you send it in chunks of 4-5 seconds, it will play it that way too.
@avin3sh , Can you please give me the code example as I am not able to find it out anywhere?
@zoutepopcorn , I checked your code and it's not related to chunk based audio play at all.
Yes it is possible
Server
io.on('connection', function (socket) { socket.on('client-stream-request', function (data) { var stream = ss.createStream(); var filename = __dirname + '/downloads/' + <YOURSONG.MP3>; ss(socket).emit('audio-stream', stream, { name: filename }); fs.createReadStream(filename).pipe(stream); }); });
Client
var audio = document.getElementById('player'); ss(socket).on('audio-stream', function(stream, data) { parts = []; stream.on('data', function(chunk){ parts.push(chunk); }); stream.on('end', function () { audio.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts)); audio.play(); }); });
Could you do that client -> server -> client? Like a peer-to-peer voice chat? Just trying to make something for my non-programmer friends.
@jojomoore2007 For that use case I would recommend using WebRTC or something similar, it would scale much better and would be a true peer to peer implementation as opposed to the server middleman.
Hello Streaming music synchronously from an mp3 file via an Angular + socket. io I have an mp3 file on my server.
And I want all my clients who visit that URL to listen to that music in sync.
That is.
Let's say the file plays for 6 minutes.
I start the song at 10:00 am
A request which comes at 10:03 am should start listening from the 3rd minute of the song.
All my clients should listen to the song in sync.
How can I achieve this with Angular and socket.io?
Hello Streaming music synchronously from an mp3 file via an Angular + socket. io I have an mp3 file on my server.
And I want all my clients who visit that URL to listen to that music in sync.
That is.
Let's say the file plays for 6 minutes.
I start the song at 10:00 am
A request which comes at 10:03 am should start listening from the 3rd minute of the song.
All my clients should listen to the song in sync.
How can I achieve this with Angular and socket.io?
Hi @viradiya1993 , did you get any solution for this?
isten to the song in sync.
I also need a solution for this. does anyone know how to implement this?
Is it possible to Stream Audio form the Server to the client ? Is there any example please ?