Jonatan Lavado
Jonatan Lavado

Reputation: 1084

Not playable audio file stored in laravel lumen

I have a mp3 audio file stored in public/storage folder which is linked from storage/app/public folder, simulating the php artisan storage:link with this command.

So, now I can access directly in the browser like this doing http://my-domain/storage/example.mp3 in my browser. I get the audio, but isn't playable, I don't know why.

When I type http://my-domain/storage/example.mp3 in my browser I get this:

enter image description here

The audio isn't corrupted because I tried to move it manually from it's path public/storage (with WinSCP) to my window's desktop and it plays normal. I don't know what's happening with this. Can someone help me?

Edit: I also tried to make a get route to play the audio, so I did something like this:

public function getAudio(Request $request, $filename){

    if(!Storage::disk('public')->exists($filename)){
           return "error";
    } 
    try {
       $type = Storage::mimeType($filename);
       $file = Storage::get($filename);

       return response($file, 200)->header('Content-Type', $type);

    } catch (\Exception $e){
       return $e->getMessage();
    }

}

But I'm getting the same as the screenshot...

Edit: It only happens with audio files, with .txt files it shows me the file content and also with images, works fine.

Upvotes: 1

Views: 611

Answers (1)

Jonatan Lavado
Jonatan Lavado

Reputation: 1084

It was a problem with the mp3 file, I don't know about formats but I used ffmpeg from ffmpeg, to convert the audio file to .ogg and it worked. I'm still confused why the mp3 file wasn't playable.

Upvotes: 0

Related Questions