我正在编写一个dhtml应用程序,用于创建系统的交互式模拟。用于模拟的数据是从另一个工具生成的,并且已经有大量的遗留数据。
模拟中的一些步骤要求我们播放音频的“画外音”剪辑。我一直无法找到一种跨越多个浏览器的简单方法来完成此任务。
Soundmanager2非常接近我所需要的,但它只能播放mp3文件,而且遗留数据也可能包含一些.wav文件。
有没有人有其他库可以帮上忙?
发布于 2008-10-09 14:05:13
您将不得不包括一个插件,如Real Audio或QuickTime来处理.wav文件,但这应该可以工作…
//======================================================================
var soundEmbed = null;
//======================================================================
function soundPlay(which)
{
if (!soundEmbed)
{
soundEmbed = document.createElement("embed");
soundEmbed.setAttribute("src", "/snd/"+which+".wav");
soundEmbed.setAttribute("hidden", true);
soundEmbed.setAttribute("autostart", true);
}
else
{
document.body.removeChild(soundEmbed);
soundEmbed.removed = true;
soundEmbed = null;
soundEmbed = document.createElement("embed");
soundEmbed.setAttribute("src", "/snd/"+which+".wav");
soundEmbed.setAttribute("hidden", true);
soundEmbed.setAttribute("autostart", true);
}
soundEmbed.removed = false;
document.body.appendChild(soundEmbed);
}
//======================================================================
发布于 2008-10-09 13:11:57
如果您正在使用Prototype,可以使用Scriptacars库has a sound API。jQuery appears to have a plugin也是。
发布于 2009-12-20 15:59:15
dacracots代码是干净的基本dom,但也许没有经过深思熟虑就写出来了?当然,您首先检查是否存在较早的嵌入,然后保存重复的嵌入创建行。
var soundEmbed = null;
//=====================================================================
function soundPlay(which)
{
if (soundEmbed)
document.body.removeChild(soundEmbed);
soundEmbed = document.createElement("embed");
soundEmbed.setAttribute("src", "/snd/"+which+".wav");
soundEmbed.setAttribute("hidden", true);
soundEmbed.setAttribute("autostart", true);
document.body.appendChild(soundEmbed);
}
在扫描类似情况的解决方案时,我在这里遇到了这个想法。不幸的是,我的浏览器Mozilla/5.0 (X11;U;Linux i686;en-US;rv:1.9.0.15) Gecko/2009102814 Ubuntu/8.04 (hardy) Firefox/3.0.15在尝试时死掉了。
安装最新更新后,firefox仍然崩溃,opera仍然存活。
https://stackoverflow.com/questions/187098
复制相似问题