I need to play a mp3 audio file when the user clicks on a image. I only want to audio to play, i.e. there should be no controls, widgets, etc. Nor should the browser launch an external application.
Edit: ok, I might be able to try out flash. recommendations for a lightweight flash player?
The audio tag allows you to embed audio content in your HTML pages. By default the browser does not show any controls for this element. Which means the audio will play only if set to autoplay (more on this later) and the user can't see how to stop it, or control the volume or move through the track.
The HTML <audio> autoplay attribute is used to specify that the audio should automatically start playing as soon as it is loaded. It is a Boolean attribute.
The hidden attribute hides the <audio> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <audio> element is not visible, but it maintains its position on the page.
The HTML <audio> element is used to play an audio file on a web page.
Now there's a way to do it. Put this: <audio src="sounds/game-welcome.mp3" style="display:none;" autoplay>
(Replace sounds/game-welcome.mp3 with your file)
You could do this:
<embed src="blah.wav" autostart=false loop=false>
... but playing sound without flash is evil and will lead to issues cross browser even if there is some solutions.
You could also use HTML5 and the audio tag:
<audio src="horse.ogg" controls="controls">
Your browser does not support the audio element.
</audio>
... but this won't be supported by all browsers.
EDIT: For a flash player you could use this one or this very simple one... there are tons! Try out examples and see what's best for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With