Express, Node, Angular send audio file to front end

I try to serve audio files from the end of Node / Express, to Angular.

Server Side Code:

var file = "/filepath.wav";
res.download(file, 'testAudio.wav');

Client Side Code:

var testData = null;

this.getBasicAudio = function(){
  console.log("Requesting File");
  $http.get('/getBasicAudio', "FilePathRequest")
  //Success, return the file
  .success(function(data){
    console.log("File retrive Successful");
    testData = data;
    return true;
  })
  //Error, file not retrived 
  .error(function(data){
    console.log("File retrive Failed");
    return false;
  });
};

This returns the file in order.

I am trying to load this into an Audio object, as if I were pasting a link to a file.

var audio = new Audio(testData);

But the object is null. From what I understand, I am returning a stream object from an expression, but I cannot find how to turn this into a reproducible sound.

edit: Is this because express loading () only works with non-binary data?

Thank!

+4
source share
2 answers

, : https://github.com/obastemur/mediaserver

:

:

http.createServer(function(req,res){
  ms.pipe(req,res,"../../Node/TWLW/audio/examples/testAudio.mp3");
}).listen(1337, '127.0.0.1');

:

var audio = new Audio('http://127.0.0.1:1337/');
audio.play();

Express . URL:

app.get('/music.mp3',function(req,res){
  ms.pipe(req, res, '../../Node/TWLW/audio/examples/testAudio.mp3');
});

var audio = new Audio('http://127.0.0.1:8080/testAudio.mp3');
+1

.

mySound = ([URLString]);

URL, . :

var audio = new Audio('/getBasicAudio');
audio.play(); // your audio file should play

, .

0

Source: https://habr.com/ru/post/1629863/


All Articles