In fact you are not "playing a . mp3 in php", I believe that to achieve this the player itself should be built in PHP, I don’t even know if there’s such a thing.
But I understand what you mean.
Your code just "displays" a text for the user, using the echo
. This "text" is an HTML.
One solution would be to use the audio
HTML instead of embed
as:
<audio id="audio" autoplay>
<source src="11.mp3" type="audio/mp3" />
</audio>
You want a demonstration?!
<audio id="audio" autoplay controls>
<source src="https://cdns-preview-8.dzcdn.net/stream/821246fb5d7e2ff6975f65ef7460a708-0.mp3" type="audio/mp3">
</audio>
The function audio
has several different attributes, including in this example the controls
(to display the controls, pause and such) and the autoplay
(to start automatically). You can all attributes here. ;)
The music preview, used in the example, was extracted from the API of Deezer, right here.
You DON’T NEED PHP for this.
If you really want to use PHP to display, you can use:
echo '<audio id="audio" autoplay>
<source src="11.mp3" type="audio/mp3" />
</audio>';
There are other alternatives, but it doesn’t go away.
Also check the Console (F12 in Google Chrome) and enter "Network" and see if he is getting the file 11.mp3. If it is 404, or any value other than 200, it may not be able to find the file 11.mp3.