博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript声音播放
阅读量:4625 次
发布时间:2019-06-09

本文共 1290 字,大约阅读时间需要 4 分钟。

方式一:

/** * 播放音频(Chrome、opera)支持 * @param file:支持 rm,mid,wav */function  playAudio(file) {   var embed=document.getElementById("bgsoundid");   if(embed){      document.removeChild(embed);   }    embed = document.createElement("embed");   embed.setAttribute('id', "bgsoundid");   embed.setAttribute('src', file);   embed.setAttribute('hidden', true);   embed.setAttribute('autostart', true);   embed.setAttribute('loop', "1");   document.body.appendChild(embed);}

方式二:

/** * Iframe实现声音播放(兼容:IE、firefox、chrome、Opera) * @param file 支持 rm,mid,wav,*基本上都支持 */function iframeAudio(file){  var iframe=document.getElementById("audioIframe");  if(iframe) {    document.removeChild(iframe);  }  iframe = document.createElement("iframe");  iframe.setAttribute('id', "audioIframe");  iframe.setAttribute('src', file);  iframe.setAttribute('height', "0");  iframe.setAttribute('width', "0");  iframe.setAttribute('border', "0");  document.body.appendChild(iframe);}

 

方式三:

方式四:

使用soundManageer2插件,下载地址:

var  soundManager=soundManager.createSound({  id: 'mySound',  url: '/path/to/some.mp3',  autoLoad: true,  autoPlay: false,  onload: function() {    alert('The sound '+this.id+' loaded!');  },  volume: 50});//播放soundManager.play();//停止soundManager.stop();

 

 

转载于:https://www.cnblogs.com/boonya/p/3299156.html

你可能感兴趣的文章
怎么开手动档轿车?这么开让你再也不想开自动档
查看>>
FileSystemXmlApplicationContext、ClassPathXmlApplicationContext和XmlWebApplicationContext简介
查看>>
java native方法及JNI实例
查看>>
9_2019.04.20随记
查看>>
29 最小的K个数
查看>>
10款免费且开源的项目管理工具
查看>>
thinkphp数据查询方法总结select ,find,getField,query
查看>>
Spring Boot控制上传文件大小
查看>>
Wannafly挑战赛22 A计数器(裴蜀定理 gcd)
查看>>
day22作业详解
查看>>
Codeforces 10D
查看>>
charles抓包
查看>>
新手上路注意事项及驾车技巧
查看>>
关于Block汇总
查看>>
freemarker 学习一 入门小例子
查看>>
获取bing每日图片
查看>>
图解Docker容器和镜像
查看>>
android studio gradle 两种更新方法更新
查看>>
Java语言的垃圾回收机制
查看>>
Android中绘制圆角矩形图片及任意形状图片
查看>>