跨平台,跨浏览器的方式从Javascript播放声音? [英] Cross-platform, cross-browser way to play sound from Javascript?

查看:136
本文介绍了跨平台,跨浏览器的方式从Javascript播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写,创建一个系统的交互仿真DHTML应用程序。用于模拟的数据是从另一种工具生成的,并且已经有非常大量的遗留数据的

I am writing a dhtml application that creates an interactive simulation of a system. The data for the simulation is generated from another tool, and there is already a very large amount of legacy data.

在模拟中的某些步骤要求我们播放音频的画外音剪辑。我一直无法找到一个简单的方法来在多个浏览器做到这一点。

Some steps in the simulation require that we play "voice-over" clips of audio. I've been unable to find an easy way to accomplish this across multiple browsers.

Soundmanager2 自带pretty接近我所需要的,但它只能播放MP3文件,以及传统的数据可能包含某些.wav文件以及。

Soundmanager2 comes pretty close to what I need, but it will only play mp3 files, and the legacy data may contain some .wav files as well.

没有人有任何其他库,可以帮助?

Does anyone have any other libraries that might help?

推荐答案

您必须包括一个插件如Real音频或QuickTime来处理.wav文件,但这应该工作...

You will have to include a plug-in like Real Audio or QuickTime to handle the .wav file, but this should work...

//======================================================================
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);
    }
//======================================================================

这篇关于跨平台,跨浏览器的方式从Javascript播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆