将声音整合到网站的最佳方式

时间:2021-04-30 15:16:07

I am looking to integrate sound into a website. Basically a chat website where users will hear a sound when a new message arrives. What do you think is the best way to integrate sound?

我希望将声音整合到一个网站中。基本上是一个聊天网站,用户在收到新消息时会听到声音。您认为整合声音的最佳方式是什么?

  1. Javascript to play the sound
  2. Javascript播放声音

  3. Javascript to call a flash swf which plays the sound
  4. Javascript调用播放声音的flash swf

  5. Any other method I cant think of?
  6. 还有其他任何我想不到的方法吗?

Thank you for your time.

感谢您的时间。

9 个解决方案

#1


A small swf with the sound controlled by javascript would the the way to go in terms of being cross platform and cross browser.

由javascript控制声音的小型swf将成为跨平台和跨浏览器的方式。

#2


I would go with option #2. But, with a word of caution when integrating any sound into a web site, people often find it annoying, when a sound comes out of the blue.

我会选择#2。但是,在将任何声音整合到网站时要小心谨慎,当声音突然出现时,人们常常觉得很烦人。

#3


As Conrad said, use javascript and swf. You can also take a look at what other people use. One example that I like is the Campfire chat. It works in all browsers and OS:es that I've tried it with.

正如康拉德所说,使用javascript和swf。您还可以查看其他人使用的内容。我喜欢的一个例子是Campfire聊天。它适用于所有浏览器和操作系统:我尝试过它。

#4


The most elegant solution would be to use the upcoming HTML5 <audio> tag. You can script this from JavaScript. Support for this is poor, however.

最优雅的解决方案是使用即将推出的HTML5

As as said by others, the alternative would be a Flash solution.

正如其他人所说,替代方案将是Flash解决方案。

I would recommend using the <audio> tag where possible and Flash as fallback content.

我建议尽可能使用

#5


I personally don't like websites that need JavaScript activated to accomplish something in Flash (eg. youtube), because generally speaking I have deactivated JavaScript. Therefore I would suggest to only use Flash. However this is a personal thing. Most users probably don't mind.

我个人不喜欢需要激活JavaScript才能在Flash中完成某些事情的网站(例如youtube),因为一般来说我已经停用了JavaScript。因此我建议只使用Flash。然而,这是个人的事情。大多数用户可能不介意。

#6


Personally I don't like background music or sounds on websites. Reminds me of the bad old days were every site had a background MIDI file on it.

就个人而言,我不喜欢网站上的背景音乐或声音。让我想起过去每个网站都有背景MIDI文件的糟糕时光。

At least have the option to switch it off :)

至少可以选择关闭它:)

#7


3 Use Flash. It's widely supported and it works better than Java applets.

Please make a clearly visible mute button too! :)

请制作一个清晰可见的静音按钮! :)

#8


This is a very nice API that uses flash and javascript to make embedding sound in your webpages easy as something very easy: http://www.schillmania.com/projects/soundmanager2/

这是一个非常好的API,它使用flash和javascript在您的网页中轻松嵌入声音非常简单:http://www.schillmania.com/projects/soundmanager2/

#9


Setting aside the ethics of whether to make a sound play in a web page automatically...

撇开是否自动在网页上发声的道德规范......

I've got this working with XHTML 1.0 Strict in FF 3.x+, Opera 9.x+, IE6+, but not in Chrome (3.0.195.38) or Safari (4.0.4). So, I can't figure out how to get Webkit to accept it. Note this likely will not pass XHTML validation. And also note that my doctype stuff starts off like this:

我在FF 3.x +,Opera 9.x +,IE6 +中使用XHTML 1.0 Strict,但在Chrome(3.0.195.38)或Safari(4.0.4)中没有。所以,我无法弄清楚如何让Webkit接受它。请注意,这可能无法通过XHTML验证。还要注意我的doctype东西开头是这样的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Anyway, although the following code doesn't work yet in Webkit browsers, it works in other browsers:

无论如何,虽然以下代码在Webkit浏览器中不起作用,但它适用于其他浏览器:

<bgsound src="http://example.com/sound.wav" loop="0" />
<audio src="http://example.com/sound.wav" autoplay loop="false" />

If anyone know how to get this working in Webkit browsers, I'd like to know how.

如果有人知道如何在Webkit浏览器中使用它,我想知道如何。

#1


A small swf with the sound controlled by javascript would the the way to go in terms of being cross platform and cross browser.

由javascript控制声音的小型swf将成为跨平台和跨浏览器的方式。

#2


I would go with option #2. But, with a word of caution when integrating any sound into a web site, people often find it annoying, when a sound comes out of the blue.

我会选择#2。但是,在将任何声音整合到网站时要小心谨慎,当声音突然出现时,人们常常觉得很烦人。

#3


As Conrad said, use javascript and swf. You can also take a look at what other people use. One example that I like is the Campfire chat. It works in all browsers and OS:es that I've tried it with.

正如康拉德所说,使用javascript和swf。您还可以查看其他人使用的内容。我喜欢的一个例子是Campfire聊天。它适用于所有浏览器和操作系统:我尝试过它。

#4


The most elegant solution would be to use the upcoming HTML5 <audio> tag. You can script this from JavaScript. Support for this is poor, however.

最优雅的解决方案是使用即将推出的HTML5

As as said by others, the alternative would be a Flash solution.

正如其他人所说,替代方案将是Flash解决方案。

I would recommend using the <audio> tag where possible and Flash as fallback content.

我建议尽可能使用

#5


I personally don't like websites that need JavaScript activated to accomplish something in Flash (eg. youtube), because generally speaking I have deactivated JavaScript. Therefore I would suggest to only use Flash. However this is a personal thing. Most users probably don't mind.

我个人不喜欢需要激活JavaScript才能在Flash中完成某些事情的网站(例如youtube),因为一般来说我已经停用了JavaScript。因此我建议只使用Flash。然而,这是个人的事情。大多数用户可能不介意。

#6


Personally I don't like background music or sounds on websites. Reminds me of the bad old days were every site had a background MIDI file on it.

就个人而言,我不喜欢网站上的背景音乐或声音。让我想起过去每个网站都有背景MIDI文件的糟糕时光。

At least have the option to switch it off :)

至少可以选择关闭它:)

#7


3 Use Flash. It's widely supported and it works better than Java applets.

Please make a clearly visible mute button too! :)

请制作一个清晰可见的静音按钮! :)

#8


This is a very nice API that uses flash and javascript to make embedding sound in your webpages easy as something very easy: http://www.schillmania.com/projects/soundmanager2/

这是一个非常好的API,它使用flash和javascript在您的网页中轻松嵌入声音非常简单:http://www.schillmania.com/projects/soundmanager2/

#9


Setting aside the ethics of whether to make a sound play in a web page automatically...

撇开是否自动在网页上发声的道德规范......

I've got this working with XHTML 1.0 Strict in FF 3.x+, Opera 9.x+, IE6+, but not in Chrome (3.0.195.38) or Safari (4.0.4). So, I can't figure out how to get Webkit to accept it. Note this likely will not pass XHTML validation. And also note that my doctype stuff starts off like this:

我在FF 3.x +,Opera 9.x +,IE6 +中使用XHTML 1.0 Strict,但在Chrome(3.0.195.38)或Safari(4.0.4)中没有。所以,我无法弄清楚如何让Webkit接受它。请注意,这可能无法通过XHTML验证。还要注意我的doctype东西开头是这样的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Anyway, although the following code doesn't work yet in Webkit browsers, it works in other browsers:

无论如何,虽然以下代码在Webkit浏览器中不起作用,但它适用于其他浏览器:

<bgsound src="http://example.com/sound.wav" loop="0" />
<audio src="http://example.com/sound.wav" autoplay loop="false" />

If anyone know how to get this working in Webkit browsers, I'd like to know how.

如果有人知道如何在Webkit浏览器中使用它,我想知道如何。