开发者

Html: play audio without controls?

开发者 https://www.devze.com 2022-12-13 08:18 出处:网络
I need to play a mp3 audio file when the us开发者_运维技巧er 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

I need to play a mp3 audio file when the us开发者_运维技巧er 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?


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.


I'm not sure if you can still benefit from these, but SoundManager 2 and jPlayer are two easy to use audio players. Both are instantiated using JavaScript, call a Flash file behind the scenes, and can be styled using HTML and CSS.


Let me correct this. With HTML5 .ogg file will play in FireFox only. Adding Controls element will display controls, to hide controls simply do not add controls element, but again it will only work in FireFox with .ogg file. FireFox does not support MP3 files in HTML5, only Chrome and Safari so far, may be IE9 will later. Your best bet is Flash. Good luck.


just do this:

controls="false"

it's a boolean value

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号