使用jQuery 1.4播放声音的跨平台,跨浏览器方式?

时间:2021-09-23 12:17:26

I'm trying to get jQuery to play a sound on element hover/click. (It's like a flash website without flash)

我试图让jQuery在元素悬停/点击上播放声音。 (这就像没有闪存的Flash网站)

I've tried the methods recommended in Cross-platform, cross-browser way to play sound from Javascript?, the jQuery Sound plugin and a couple of other tutorials without any success. I'm assuming this is because they haven't been updated since 2008.

我尝试过跨平台,跨浏览器方式推荐的方法,从Javascript播放声音,jQuery Sound插件和其他一些教程没有任何成功。我假设这是因为他们自2008年以来没有更新过。

Does anyone have any recommendations?

有人有什么建议吗?

5 个解决方案

#1


33  

Don't need any of those. The HTML tag, combined with JavaScript, will do the trick.

不需要任何这些。 HTML标记与JavaScript结合使用即可。

<audio id="soundHandle" style="display: none;"></audio>
<script>
  soundHandle = document.getElementById('soundHandle');
  soundHandle.src = '/blah/blah.mp3';
  soundHandle.play();
</script>

#2


6  

Actually it's impossible to do in a truly cross-browser compliant way as for example iPhones will play sound only on a dedicated player "page". However some of the plugins in the other answers should do the job for most (desktop) browsers.

实际上,不可能以真正的跨浏览器兼容方式进行,例如iPhone只能在专用播放器“页面”上播放声音。但是,其他答案中的某些插件应该可以完成大多数(桌面)浏览器的工作。

#3


5  

Audio tag did not work for me in some browsers so this is how I got it done:

音频标签在某些浏览器中对我不起作用,所以这就是我完成它的方法:

function playBuzzer(){
        $("body").append("<embed src='/web/sounds/Buzz.mp3' autostart='true' loop='false' width='2' height='0'></embed>");
}

Whenever I want to play sound (onmouseover, onclick, onload...) I call this function.

每当我想播放声音(onmouseover,onclick,onload ......)时,我都会调用此函数。

#4


2  

try this: http://swaggplayer.no.de/demos it using the flash to play a sound or this one http://www.schillmania.com/projects/soundmanager2/

试试这个:http://swaggplayer.no.de/demos它使用闪光灯播放声音或这一个http://www.schillmania.com/projects/soundmanager2/

#5


0  

http://codecanyon.net/item/fancy-music-player-v20-jquery-plugin/498071?ref=1stwebdesigner

http://codecanyon.net/item/fancy-music-player-v20-jquery-plugin/498071?ref=1stwebdesigner

Player works like this - first it detects if Flash Player 9 or higher is installed. If yes a hidden flash movie(swf) will be used, that communicates via javascript with the HTML user interface. If no Flash Player is installed, the new HTML5 audio engine will be used, which is supported by all iToys(iPhone, iPad etc.).

播放器的工作原理如下 - 首先它会检测是否安装了Flash Player 9或更高版本。如果是,将使用隐藏的flash电影(swf),通过javascript与HTML用户界面进行通信。如果没有安装Flash Player,将使用新的HTML5音频引擎,所有iToys(iPhone,iPad等)都支持该引擎。

#1


33  

Don't need any of those. The HTML tag, combined with JavaScript, will do the trick.

不需要任何这些。 HTML标记与JavaScript结合使用即可。

<audio id="soundHandle" style="display: none;"></audio>
<script>
  soundHandle = document.getElementById('soundHandle');
  soundHandle.src = '/blah/blah.mp3';
  soundHandle.play();
</script>

#2


6  

Actually it's impossible to do in a truly cross-browser compliant way as for example iPhones will play sound only on a dedicated player "page". However some of the plugins in the other answers should do the job for most (desktop) browsers.

实际上,不可能以真正的跨浏览器兼容方式进行,例如iPhone只能在专用播放器“页面”上播放声音。但是,其他答案中的某些插件应该可以完成大多数(桌面)浏览器的工作。

#3


5  

Audio tag did not work for me in some browsers so this is how I got it done:

音频标签在某些浏览器中对我不起作用,所以这就是我完成它的方法:

function playBuzzer(){
        $("body").append("<embed src='/web/sounds/Buzz.mp3' autostart='true' loop='false' width='2' height='0'></embed>");
}

Whenever I want to play sound (onmouseover, onclick, onload...) I call this function.

每当我想播放声音(onmouseover,onclick,onload ......)时,我都会调用此函数。

#4


2  

try this: http://swaggplayer.no.de/demos it using the flash to play a sound or this one http://www.schillmania.com/projects/soundmanager2/

试试这个:http://swaggplayer.no.de/demos它使用闪光灯播放声音或这一个http://www.schillmania.com/projects/soundmanager2/

#5


0  

http://codecanyon.net/item/fancy-music-player-v20-jquery-plugin/498071?ref=1stwebdesigner

http://codecanyon.net/item/fancy-music-player-v20-jquery-plugin/498071?ref=1stwebdesigner

Player works like this - first it detects if Flash Player 9 or higher is installed. If yes a hidden flash movie(swf) will be used, that communicates via javascript with the HTML user interface. If no Flash Player is installed, the new HTML5 audio engine will be used, which is supported by all iToys(iPhone, iPad etc.).

播放器的工作原理如下 - 首先它会检测是否安装了Flash Player 9或更高版本。如果是,将使用隐藏的flash电影(swf),通过javascript与HTML用户界面进行通信。如果没有安装Flash Player,将使用新的HTML5音频引擎,所有iToys(iPhone,iPad等)都支持该引擎。