Best way to play wav files in the browser?

半腔热情 提交于 2019-12-03 11:45:52

Nowadays, the best way is probably just to use the HTML5 <audio> tag. In the past, you might have done it like this:

Background:

<embed src="bgsound.wav" hidden="true" autostart="true" loop="1">

On Click:

<a href="success.wav">Play Sound</a>

It's been a few years since the last answer. Embed tag was good but I had an issue trying to trigger it to play in JavaScript. New audio tag works well is most browsers.

<audio src="cat9.wav" preload></audio>

You can trigger it manually with audioElement.play()

<audio controls="controls"><source src="http://blablabla.com/hghghgh/my%20file.wav" type="audio/x-wav" /></audio>

Due to unfixed bug (issue from 2012 year?) sometimes Chromium-like browsers cannot play .wav from redirected URLs because they "think" that file size is zero. But .mp3 is OK.

Opera 12.14 and Firefox play from < audio > tag normally in the same case (redirected URL).

I tried JPlayer's 2.9.* lib in Drupal 7 with 3 players, but not successful (was black inactive rectangle 300*14 pixels for each player).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!