koajs / discussions

KoaJS Discussions
2 stars 2 forks source link

Hosting mp3 file #11

Open Ch0ikyle opened 4 years ago

Ch0ikyle commented 4 years ago

I'm coding API server to be used in mp3 app. I've used koa-send, koa-static, and just setting mp3 file to response-body.

But, no matter what API the app uses, the app stops. When I sent the length of the MP3 file separately because the app did not seem to accept the length of the MP3 file, it worked on iOS but not on Android.

If I post the same MP3 file on S3 and send request to that URL, it worked well, so I can't understand what the problem is.

Also, if I play music on Safari using my API, it comes out as a live broadcast. (using other sites, it comes in the form of mp3)

If it's a problem that you don't know how long it's playing, why is it the same file, but not on other sites, and not on my API?

Other storage site:

other storage site

My API:

my API

ralyodio commented 4 years ago

i think you'll want to serve out of a static directory for mp3. Checkout how to set a static directory with koa-router.

adjenks commented 4 years ago

The server and the browser both need to implement "Range Requests". The audio tag for many browsers make ranged requests when you seek ahead. The server also needs to report the file size. Koa is middleware based, you have to find middleware that will serve static files and will support range requests.

Audio tag documentation mentioning range requests: https://www.w3.org/TR/html52/semantics-embedded-content.html#example-3abe9ec8

MDN docs about range requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

Actually I just looked for you, it turns out many libraries use koa-send, which does not support range requests: https://github.com/koajs/send/issues/84

Someone in that issue however points out that you can add range support using this middleware: https://github.com/koajs/koa-range