3

I'm streaming audio files from a Node.js Express server with Content-Range headers plus no caching headers. This works ok in latest Safari instead, but it does not in Chrome.

While when streaming the full audio file with HTTP 200, my headers were

{ 'Content-Length': 4724126,
  'Content-Type': 'audio/mpeg',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
  'Access-Control-Allow-Headers': 'POST, GET, OPTIONS',
  Expires: 0,
  Pragma: 'no-cache',
  'Cache-Control': 'no-cache, no-store, must-revalidate' }

and it works on both Chrome and Safari <audio> tag.

When streaming partial contents with HTTP 206 the headers were

{ 'Content-Length': 4724126,
  'Content-Type': 'audio/mpeg',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
  'Access-Control-Allow-Headers': 'POST, GET, OPTIONS',
  Expires: 0,
  Pragma: 'no-cache',
  'Cache-Control': 'no-cache, no-store, must-revalidate',
  'Accept-Ranges': 'bytes',
  'Content-Range': 'bytes 120515-240260/4724126' }

This led to an error of the Chrome page where the <audio> or <video> tag was.

Even the embedded media tag created by Chrome when using the streaming url right in the browser it is not working, and led to this

enter image description here

The audio file is served reading a local file and creating a file read stream via Node.js the createReadStream api:

var file = fs.createReadStream(path, {start: range[0], end: range[1]});

I have posted the code for the server here.

[UPDATE]

It turns not that Chrome is more strict about Range and Content-Range requests/responses. So any Content-Range response must have a Range previous request. The typical case is scrubbing a player bar to the second S. The api will send a "Range" request, the server will respond with a "Content-Range" header. In my case I was sending a Content-Range response over an ordinary request without "Range". Safari works because is more street-html complaint i.e. it does not strictly require a "Range" request before a "Content-Range" response. So, I removed the "Content-Range" header from my response, and not it works. End of the story (!).

To follow up this issue I have posted in Chromium net-dev forum too in Chrome bad Range header: Range: bytes=0-

loretoparisi
  • 15,724
  • 11
  • 102
  • 146
  • 1
    Any reason on why you are doing the back-end with NodeJS ? what about relying on say NGINX to do the heavy lifting for you ? By the way what player did you use? – OAH Dec 23 '19 at 15:03
  • 1
    @OAH I'm using the default HTML5 player in the browser in most of cases. Other players I have tested it are: BBC Peak.js (https://waveform.prototyping.bbc.co.uk/), WaveSurfer.js (https://wavesurfer-js.org/). I prefer to handle this within node.js because I have to modify the handle / modify the response bytes as well of the audio (like changing sampling, etc.), so I recalculate the range based on the request type in node. – loretoparisi Sep 22 '20 at 07:15
  • 1
    aha, i see now. – OAH Sep 23 '20 at 02:48

0 Answers0