Laravel/lumen return audio for html audio player

48 views Asked by At

In my Lumen app I'm getting audio file from external Lumen service and saving it in Storage.

$tempname = tempnam(sys_get_temp_dir(), 'response').'.mp3';

Http::sink($tempname)->get(myExternalResourceUrl);

Storage::putFile('/public', new File($tempname));
$path = Storage::path($tempname);

return response()->download($path, 'myAudio.mp3', ['Content-Type' => 'audio/mp3']);

Also I've checked my saved files in storage and they don't have any problems. I think I cannot use here just link to my file in storage because I should delete it after receiving in frontend.

On my frondent (vue.js) I've tried to do this:

<audio>
  <source :src="audio.resource">
</audio>

promiseToDownload.then(data => {
   const url = window.URL.createObjectURL(new Blob([data]), {type: 'audio/mp3'});

   this.audio.resource = url;
});

I have no errors, but my audio is simply doesn't work. It shows only zeroes on audio time. Begging for help

I've tried to replace response()->download($path, 'myAudio.mp3', ['Content-Type' => 'audio/mp3']) with Storage::download($tempname); but it also doesn't work.

0

There are 0 answers