天下之事,必先处之难,而后易之。

JavaScript声音播放

方式一:

/**
 * 播放音频(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);
}

 

方式三:

<bgsound loop='10' src='../res/audio/alarm.wav'>


方式四:

使用soundManageer2插件,下载地址:http://www.schillmania.com/projects/soundmanager2/#getting-started

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();

 

 

posted @ 2013-09-03 17:30  boonya  阅读(2037)  评论(1)    收藏  举报
我有佳人隔窗而居,今有伊人明月之畔。
轻歌柔情冰壶之浣,涓涓清流梦入云端。
美人如娇温雅悠婉,目遇赏阅适而自欣。
百草层叠疏而有致,此情此思怀彼佳人。
念所思之唯心叩之,踽踽彳亍寤寐思之。
行云如风逝而复归,佳人一去莫知可回?
深闺冷瘦独自徘徊,处处明灯影还如只。
推窗见月疑是归人,阑珊灯火托手思忖。
庐居闲客而好品茗,斟茶徐徐漫漫生烟。

我有佳人在水之畔,瓮载渔舟浣纱归还。
明月相照月色还低,浅近芦苇深深如钿。
庐山秋月如美人衣,画堂春阁香气靡靡。
秋意幽笃残粉摇曳,轻轻如诉画中蝴蝶。
泾水潺潺取尔浇园,暮色黄昏如沐佳人。
青丝撩弄长裙翩翩,彩蝶飞舞执子手腕。
香带丝缕缓缓在肩,柔美体肤寸寸爱怜。
如水之殇美玉成欢,我有佳人清新如兰。
伊人在水我在一边,远远相望不可亵玩。