Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play mp3 on link click

There is a simple link

<a href="some.mp3">01. The Name of Track</a>

How to play the mp3 file, when user clicks on link? Please help me to find some simple and effective solution. Thank you.


Thank you for help.

I choosed this solution http://www.schillmania.com/projects/soundmanager2/demo/play-mp3-links/ as the most appropriate in my case.

like image 360
KFox Avatar asked Dec 13 '12 18:12

KFox


People also ask

How do I make an MP3 into a link?

To link to an MP3 file, you must first upload the MP3 file either to a cloud storage service like Google Drive or iCloud, or to an online music service like SoundCloud. After uploading the music, you can share it via the link.

How do you link an MP3 to HTML?

Linking to a sound file using a href allows a browser to open and play an audio file if the viewer of your web page has properly configured their Internet browser. You can also use the <embed> tag or the newer <audio> tag to insert a sound file directly into a web page.

How do I make an audio link?

Just mark the “Embed” checkbox and press the Translate & Speak & Embed button. Translate & Speak will create an audio link ready to be embedded. Click "Copy" to copy the link to email a voiced message or embed the audio link to your website.


1 Answers

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: As audio is an HTML5 tag, it won't support old browsers, so be sure before you use it..

Or take a look at this article

like image 70
Mr. Alien Avatar answered Oct 05 '22 08:10

Mr. Alien