How to play mp3 click here
There is a simple link
<a href="some.mp3">01. The Name of Track</a> How to play an mp3 file when a user clicks on a link? Please help me find some simple and effective solution. Thanks.
Thank you for your help.
I chose this solution http://www.schillmania.com/projects/soundmanager2/demo/play-mp3-links/ as the most suitable in my case.
Many browsers today (such as Chrome and Firefox) will not play MP3 or MP4 files due to IP restrictions. You can transcode files to compatible alternatives, such as Ogg, or you have to rely on plugins to get universal browser support. One very good option is Soundmanager , which I use in a project where transcoding is not an option. It uses HTML 5 playback when possible, but returns to an invisible flash movie if the file type is not supported by the selected browser. He is extremely flexible, but he has a little learning curve. The demos are fantastic, although they provide several types of players that you can probably just go to any of your interfaces.
Use HTML5 <audio>
<audio controls id="linkAudio"> <source src="demo.ogg" type="audio/ogg"> <source src="demo.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <script> document.getElementById("link_id").addEventListener("click", function () { document.getElementById("linkAudio").play(); }); </script> Note. Since audio is an HTML5 tag, it does not support older browsers, so be sure to use it before using it.
Or look at the article
You have several options, you can use the html5 sound tag, which will create a small player that allows you to play audio:
<audio controls width="100" height="100"> <source src="some.mp3" type="audio/mp3"> <!-- Fallback for older browsers --> Your browser doesn't support html5 audio </audio> You can also use the built-in html tag:
<embed src="some.mp3" autostart="false" id="somemp3" enablejavascript="yes"> Then run the following javascript by clicking the link:
var snd = document.getElementById(somemp3); snd.play(); Or you can use the embed method for browsers that do not support html5 audio by placing the above code in sound tags, and it will only appear if the browser does not recognize the audio tag
You can also use a flash player.