Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

treadnought's avatar

Embed .mp3 in blade view

Very basic question to which I cannot find an answer: I have a set of .mp3 files that I want users to be able to click on to hear.

How do I do that?

The files are all in the storage/app/public folder and the symlink to public has been set.

I've tried the <audio controls src="..."> tag on a blade view with many different tries at the file path but I can't get it to work.

Here's the blade file:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <audio controls>
        <source src="{{ public_path('storage/sound-files/ravel-trois-chansons/ronde.mp3') }}" type="audio/mpeg">
        Your browser does not support the audio element.
    </audio>
</body>

</html>
0 likes
7 replies
LaryAI's avatar

To embed and play .mp3 files in your Blade view, you need to ensure that:

  1. The files are accessible via a public URL.
  2. You use the correct path in your <audio> tag.

Since you mentioned that your files are in storage/app/public and you have set up the storage symlink (php artisan storage:link), your files should be accessible via the storage directory in your public path.

Example:

If you have a file at storage/app/public/audio/song.mp3, it will be accessible at yourdomain.com/storage/audio/song.mp3.

Blade Example:

<audio controls>
    <source src="{{ asset('storage/audio/song.mp3') }}" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>

If you have multiple files:

@foreach ($songs as $song)
    <p>{{ $song->title }}</p>
    <audio controls>
        <source src="{{ asset('storage/audio/' . $song->filename) }}" type="audio/mpeg">
        Your browser does not support the audio element.
    </audio>
@endforeach

Checklist:

  • Make sure the file exists in storage/app/public/audio/song.mp3.
  • Make sure the storage symlink exists: public/storagestorage/app/public.
  • Use the asset('storage/...') helper to generate the correct URL.

If you follow these steps, your .mp3 files should play correctly in your Blade view.

shadkamel's avatar

hi, you just need to load the .mp3 file path and use the audio tag that Lary (AI) mentioned in above. and you can build your own music player that the controls are using Javascript for action such as (play, pause, next, etc...).

Glukinho's avatar

Show result HTML code generated in browser. Get one *.mp3 URL from it and analyse if it is wrong and what can be wrong. Try to fetch this URL with browser directly.

Snapey's avatar
Snapey
Best Answer
Level 122

public_path is a folder path, not a URL

src=" {{ public_path('storage/sound-files/ravel-trois-chansons/ronde.mp3') }}"

This must be a URL and not a path

replace with

src="{{ '/storage/sound-files/ravel-trois-chansons/ronde.mp3' }}"

as long as /public/ is your document root.

This is a relative url and does not need the full site name, but if you need that, use the asset() helper.

1 like

Please or to participate in this conversation.