[英]What are the best practices for on-demand sound?
最近,我们一直在开发某种基于Web的IM应用程序,我想询问实现消息警报音的最佳方法,最好通过JavaScript来控制它。 我们可以使用现有的任何库吗?
您可以使用html5音频标签 ,好处是您没有使用任何其他插件(quickTime,flash ...),但是浏览器必须支持音频标签
function SoundPlay (src)
{
var soundEmbed = document.createElement("audio");
soundEmbed.setAttribute("src", src);
soundEmbed.setAttribute("autoplay", 'autoplay');
soundEmbed.setAttribute("type", 'audio/mpeg');
//jQuery can help you with the removal of the audio element
$(soundEmbed).one('ended', function(evt)
{
$(evt.target).remove();
});
// or, if you are not using jQuery
soundEmbed.onended = function()
{
document.body.removeChild(soundEmbed);
};
document.body.appendChild(soundEmbed);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.