In fact you are not "playing a .mp3 in php", I believe that in order to achieve EXACTLY that the player itself should be built in PHP, I do not even know if that exists.
But I understood what you meant.
Your code only "displays" a text for the user, using echo
. This "text" is HTML.
One solution would be to use audio
of HTML instead of embed
as:
<audio id="audio" autoplay>
<source src="11.mp3" type="audio/mp3" />
</audio>
Want a demo?!
<audio id="audio" autoplay controls>
<source src="https://cdns-preview-8.dzcdn.net/stream/821246fb5d7e2ff6975f65ef7460a708-0.mp3"type="audio/mp3">
</audio>
The audio
function has several different attributes, including in this example controls
(to display the controls, pause and such) and autoplay
(to start automatically). You can add all attributes here. ;)
The preview of the song, used in the example, was taken from the Deezer API , exactly here .
You DO NOT 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 do not shy away from it.
Also check out the Console (F12 in Google Chrome) and go to "Network" and see if it is getting the 11.mp3 file. If it is 404, or any value other than 200, it might not be able to find the 11.mp3 file.