#Streaming Server

1 messages ยท Page 1 of 1 (latest)

simple beacon
#

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 ...

lavish bronze
#

okay...

simple beacon
#

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 ...

lavish bronze
#

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

simple beacon
#

Sure ... give a minute

lavish bronze
#

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

simple beacon
#
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);
simple beacon
lavish bronze
#

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

lavish bronze
#

for example Zoom call is WebRTC

#

but in your case it is only audio which is also very possible

simple beacon
#

I have the all files stored there

lavish bronze
simple beacon
#

Oh right ...

#

So, do you have a suggestion what library I can use?

lavish bronze
#

but wait, the streaming is going to be like YouTube streaming right?

simple beacon
#

Apple Music and so on

lavish bronze
#

okay, because I was doubting if WebRTC will be right for what you're trying to do

lavish bronze
#

to create WebRTC from scratch
https://webrtc.org/

#

but you will have to handle multiple RTCPeerConnection s

simple beacon
#

Great. So, after I told you that my app will going be like Spotify, do you still recommend WebRTC?

lavish bronze
#

it is for video call but I think you should be able to tweak it for the audio

lavish bronze
#

I think yes

#

Spotify music streaming is not live streaming, or does Spotify has something like live streaming audio directly from artists?

lavish bronze
#

What I know about Spotify is that artists upload their music and then people listen to the already uploaded music

simple beacon
#

Yes, exactly

lavish bronze
#

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

simple beacon
#

Oh, no. Or maybe I didn't explain correctly

#

But the important thing, you get it now, right?

lavish bronze
#

yeah

simple beacon
#

Good

lavish bronze
#

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

simple beacon
#

I'll make some new tests and I'll keep posted you

lavish bronze
#

okay ๐Ÿ‘

simple beacon
#

Thank you