怎么在网页中播放声音

iifeng 2009-06-15 01:45:05
前提:
1、不是背景音乐。
2、采用JS控制,声音格式为.wav或者.mp3|.mid。
3、触发条件,比如我点一下按钮。就运行播放函数。
4、页面载入时,不播放。
5、兼容FF、IE等主流浏览器。
6、代码越简单越好。
...全文
813 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuqiyu298 2010-08-08
  • 打赏
  • 举报
回复
感谢楼主,感谢各位的回复,受益匪浅
Msxindl_Com 2009-06-15
  • 打赏
  • 举报
回复

<script language="javascript">
function playmusic(){
var xx=document.getElementById("bgsound").src;
var url="http://www.tc122.com/bbsxp/UpFile/UpAttachment/2009-4/200942803450.mp3";
//我叫小沈阳 dj
if(xx==""){
document.getElementById("bgsound").src=url;
document.getElementById("musicbtn").value="停止播放";
}else{
document.getElementById("bgsound").src="";
document.getElementById("musicbtn").value="播放音乐";
}
}
</script>
<input id="musicbtn" onClick="playmusic()" value="播放音乐" type="button" />
<bgsound src="" loop="-1" id="bgsound" />
ahwingwu 2009-06-15
  • 打赏
  • 举报
回复
height=\"64\" width=\"300\ 这2个值设置小点就可以了
iifeng 2009-06-15
  • 打赏
  • 举报
回复
我想要在后台播放。不出现控制窗。
Roc_Lee 2009-06-15
  • 打赏
  • 举报
回复

function playwma()
{
var Musicurl="F:\\Music\\123.mp3";
document.writeln("<object id=\"Exobud\" type=\"application/x-oleobject\" height=\"64\" width=\"300\" ");
document.writeln("classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" name=\"MediaPlayer\">");
document.writeln(" <param name=\"url\" value=\""+Musicurl+"\" />");
document.writeln(" <param name=\"ShowControls\" value=\"1\" />");
document.writeln(" <param name=\"ShowPositionControls\" value=\"0\" />");
document.writeln(" <param name=\"ShowAudioControls\" value=\"1\" />");
document.writeln(" <param name=\"ShowTracker\" value=\"1\" />");
document.writeln(" <param name=\"ShowDisplay\" value=\"0\" />");
document.writeln(" <param name=\"ShowStatusBar\" value=\"1\" />");
document.writeln(" <param name=\"AutoSize\" value=\"0\" />");
document.writeln(" <param name=\"ShowGotoBar\" value=\"0\" />");
document.writeln(" <param name=\"ShowCaptioning\" value=\"0\" />");
document.writeln(" <param name=\"AutoStart\" value=\"1\" />");
document.writeln(" <param name=\"PlayCount\" value=\"100000\" />");
document.writeln(" <param name=\"AnimationAtStart\" value=\"0\" />");
document.writeln(" <param name=\"TransparentAtStart\" value=\"0\" />");
document.writeln(" <param name=\"AllowScan\" value=\"0\" />");
document.writeln(" <param name=\"EnableContextMenu\" value=\"0\" />");
document.writeln(" <param name=\"ClickToPlay\" value=\"0\" />");
document.writeln(" <param name=\"InvokeURLs\" value=\"1\" />");
document.writeln(" <param name=\"DefaultFrame\" value=\"datawindow\" />");
document.writeln(" <param name=\"volume\" value=\"100\" />");
document.writeln(" <embed name=\"MediaPlayer_embed\" ");
document.writeln("pluginspage=\"http://www.microsoft.com/windows/windowsmedia/download/\" ");
document.writeln("type=\"application/x-mplayer2\" ");
document.writeln("src=\""+Musicurl+"\" ");
document.writeln("width=\"300\" height=\"64\" showcontrols=\"0\" showdisplay=\"0\" showstatusbar=\"0\" ");
document.writeln("autostart=\"0\" autorewind=\"0\" showpositioncontrols=\"0\" showtracker=\"0\"> </embed>");
document.writeln("</object>");
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/alexniit4/archive/2008/08/06/2776883.aspx

87,909

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧