2

I am trying to serve a mp3 file using nodejs. The browser I am using is Google Chrome. Serving text worked but when I changed the content-heading to indicate that I want to serve mp3, it display a play button that does not play.

Here is the beginning of the information that curl -v gives me:

    * About to connect() to localhost port 2222 (#0)
    *   Trying 127.0.0.1...
    * Connected to localhost (127.0.0.1) port 2222 (#0)
    > GET / HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: localhost:2222
    > Accept: */*
    > 
    < HTTP/1.1 200 OK
    < X-Powered-By: Express
    < Content-Type: audio/mpeg
    < Content-Length: 14180
    < ETag: "336505275"
    < Date: Mon, 02 Dec 2013 10:20:03 GMT
    < Connection: keep-alive
    < 
    ��8��R�$s�PFP��0m(X�
    ���
       �ep�8���Bg*&dXȯ��"�2.���c��7�f����G�

Does anyone have any idea what I am missing to make the audio I am serving play in Google Chrome?

Here is the relevant part of the server code:

            express = require('express');
            var app = express();

            app.get('/', function (request, response) {
            var exec = require('child_process').exec,
                    child;

            child = exec('espeak -v mb-fr1 -q --pho -a 15 -p 50 -s 130 "donc ceci démontre que ça fonctionne bien" | mbrola /usr/share/mbrola/fr1/fr1 - - | lame -r -m m -b 24 -s 16 - - ',function (error, stdout, stderr) {
                    response.setHeader('Content-Type', 'audio/mpeg');
                    //response.setHeader('Transfer-Encoding', 'chunked');
                    response.send(stdout);
             }); 
            });
            module.exports = app;
Paul Mougel
  • 16,728
  • 6
  • 57
  • 64
caromimo
  • 91
  • 7
  • Could you show us the relevant parts of your server code, the output of the console and network tabs in Google Chrome? – Paul Mougel Dec 02 '13 at 13:50
  • Hi Paul. I updated my question with the relevant parts of my server code. Thanks. – caromimo Dec 02 '13 at 14:01
  • Is `error` undefined? If yes, I guess this is related to Chrome and its handling of HTTP headers. – Paul Mougel Dec 02 '13 at 14:07
  • I don't get en error in the browser, but if I look in the console, I get this message: Resource interpreted as Document but transferred with MIME type audio/mpeg: "http://localhost:2222/". Could the fact that the mp3 is interpretated as a document be part of the problem? – caromimo Dec 02 '13 at 14:14
  • Try with a route ending with `.mp3`, for instance `http://localhost/test.mp3` and `app.get('/test.mp3', function() {...`. Chrome [sometimes doesn't care of the `Content-Type` header](http://stackoverflow.com/questions/13985003/resource-interpreted-as-document-but-transferred-with-mime-type-image-jpeg) – Paul Mougel Dec 02 '13 at 14:40

0 Answers0