AngularJS stream audio from PHP server -


due cors , authentication third-party server, cannot load audio file directly angularjs , has php backend. here php server code serve audio file downloaded third-party server:

header('pragma: public');   // required header('content-type: audio/mpeg'); header('content-length: ' . filesize($file)); header("content-transfer-encoding: binary"); header('content-disposition: filename="' . basename($file)); header('x-pad: avoid browser bug'); header('cache-control: no-cache'); $len = readfile($file); exit(); 

here angularjs client code:

var blob = new blob([response], { type: 'audio/mpeg' }); var url = window.url.createobjecturl(blob); var audio = new audio(url); audio.play(); 

however fails exception message:

domexception: failed load because no supported source found. 

any advice , insight appreciated.

since you're creating audio object response anyway, there's no reason have you're doing.

instead of downloading whole response, creating blob out of it, , object url, use url you're requesting in first place. not nice efficient handling of streaming data, you'll able play while download running, and won't need cors... "opaque" response fine.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -