• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

无需安装媒体播放器扩展即可播放声音

用户头像
it1352
帮助1

问题说明

我正在尝试在拍卖网站中嵌入声音.我希望每次有人出价时,都会播放声音.我尝试了一个带有给定 ID 的简单 <embed> 标签,然后通过 javascript 尝试了 sound.play().

I am trying to embed a sound in an auction website. I want that every time someone's bid, a sound will be played. I tried a simple <embed> tag with given ID, and then sound.play() through javascript.

声音正在播放,但在 IE 中,要求新用户安装媒体播放器扩展如果他/她信任该网站".

The sound is playing, but in IE, a new user is asked to install a media player extension "if he/she trusts the website".

有没有办法让它在没有这条消息的情况下播放.页面中的代码如下:

Is there a way to make it play without this message. The following code is in the page:

在 HTML 中:

<embed src="https://www.it1352.com/success.wav" autostart="false"       
       enablejavascript="true">

在 Javascript 中:

In the Javascript:

function PlaySound(soundObj) {

  var sound = document.getElementById(soundObj);
  sound.Play();
}

以及对函数的调用:

PlaySound("sound1");

正确答案

#1

如果您愿意要求用户拥有 Flash,我推荐 SoundManager2.它在后台使用 Flash,但完全通过 JavaScript 进行配置,并且非常可定制.

If you're comfortable requiring the user to have Flash, I recommend SoundManager2. It uses Flash in the background but is configured entirely through JavaScript, and it's very customizable.

If you want to do it completely natively in the browser you can use the <audio> tag, but you'll find it only works in the very newest browsers, and there are still some cross-browser issues you're going to hit upon. This Ajaxian article gives a good overview of how to do it and which browsers support what audio formats.

附言个人意见,如果您不介意的话:不要在没有事先询问用户的情况下播放背景声音或音乐.从不自动播放,始终为用户提供停止或静音的选项.

P.S. A personal opinion, if you don't mind: Don't play background sounds or music without first asking the user. Never autoplay and always give the user the option to stop or mute the sound.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcgaehk
系列文章
更多 icon
同类精品
更多 icon
继续加载