#Streaming Server
1 messages ยท Page 1 of 1 (latest)
Hi. I'm about to start working on a Music Streaming on demand app and I'd like to get some tips ..
I'll store all mp3 files on Google Storage, build a server with nodejs to get this files and distribute to clients chunks of it ...
okay...
I started somes tests yesterday but the music only starts playing when the file was download at 6MB of 13MB ... I think it taking so much long and it cannot be a good experience for the users
Perhaps could you tell me or show me what am I doing wrong ...
I understand the issue, but I don't think I can provide any help without seeing the part of the code that's not working as expected :=)
can you share the part of the code that's not working as expected
Sure ... give a minute
and if it's streaming I would suggest you use WebRTC instead of reading the saved file chunks directly, you know that could also be a bandwidth issue for the users because it downloads data directly from the server and will also cause bad user experience when the audio is buffering because of bad connection
const range = req.headers.range || "0";
const file = storage.bucket(bucketName).file(filePath);
const [metadata] = await file.getMetadata();
const size = metadata.size as number
const CHUNK_SIZE = 500 * 1024;
let start = Number(range?.replace(/\D/g, ""));
let end = Math.min(start + CHUNK_SIZE, size - 1)
const contentLength = end - start + 1;
const headers = {
'Content-Range': `bytes ${start}-${end}/${size}`,
'Accept-Ranges': 'bytes',
'Content-Length': contentLength,
'Content-Type': 'audio/mpeg',
};
res.writeHead(206, headers);
const stream = file.createReadStream({ start, end });
stream.pipe(res);
Can I use WebRTC to provide streaming on demand to users?
you could use WebRTC to send the audio directly to the connected clients, and then you can also save the recording directly to the Cloud storage
of course that's what WebRTC is for
for example Zoom call is WebRTC
but in your case it is only audio which is also very possible
What do you mean "recording directly to the Cloud Storage" ?
I have the all files stored there
using WebRTC you will also be able to do whatever you want with the media, like saving the media to the server or to the cloud so that the user can access it later
but wait, the streaming is going to be like YouTube streaming right?
No, is going to be like Spotify
Apple Music and so on
okay, because I was doubting if WebRTC will be right for what you're trying to do
for this wait...
Janus is great, if you're an experience developer
https://janus.conf.meetecho.com/
to create WebRTC from scratch
https://webrtc.org/
An open framework for the web that enables Real-Time Communications (RTC) capabilities in the browser.
but you will have to handle multiple RTCPeerConnection s
there is another library called Jitsi-Meet
https://jitsi.org/jitsi-meet/
Great. So, after I told you that my app will going be like Spotify, do you still recommend WebRTC?
it is for video call but I think you should be able to tweak it for the audio
hmm ๐ค , please wait...
I think yes
Spotify music streaming is not live streaming, or does Spotify has something like live streaming audio directly from artists?
Its only streaming on demand
What I know about Spotify is that artists upload their music and then people listen to the already uploaded music
Yes, exactly
ohhhh sorry
it seems like I didn't get you well before, I thought you were saying live music streaming, like when an artist is singing live the audience will be able to stream the audio live
Oh, no. Or maybe I didn't explain correctly
But the important thing, you get it now, right?
yeah
Good
you can make research on how Spotify does their on demand chunk by chunk streaming, and this is what I got when I asked AI
so it means other than their server they use other technologies for their streaming
they also compress their audio before delivering it to the client which may also be part of what contributes to their high quality streaming
Thats interesting..
I'll make some new tests and I'll keep posted you
okay ๐
Thank you