当前位置: 移动技术网 > IT编程>开发语言>.net > 在主页中编制音频播放器

在主页中编制音频播放器

2018年10月17日  | 移动技术网IT编程  | 我要评论

徐小湘,最终痴汉电车next,熊猫瘦成皮包骨

虽然netscape和ie都支持音频文件的播放,但在制作过程中还是遇到了这样一个问题: 如果用隐藏方式播放则没有声卡的用户要出错,影响主页的整体效果。编一个既便于用户控制又能给页面起到点缀作用的音频播放器不失为一个好办法。下面详细介绍用javascript 自编音频播放器的方法。

  1. netscape的音频播放器

  1)直接打开

  netscape支持.mid、 .wav和.au等音频文件格式,您可以在中直接打开上述文件,打开时出现如下图的播放器窗口并自动播放一次,继续播放可单击“play”按钮。

  2)程序调用

  在主页文件中您可以嵌入如下名为mysound的音频控制台来实现隐藏方式下音频文件的自动循环播放:

  〈embed src=″jn.mid″//源文件名

  hidden=″true″//隐藏方式

  autostart=″true″//自动播放

  loop=″true″//循环播放

  name=″mysound″//嵌入对象名

  〈/embed〉

  2. javascript的音频支持函数

  通过javascript的音频支持函数,您可以控制任何一个嵌入在主页中的音频控制台。 javascript提供了如下的支持函数:

  play({loop[true,falseoranint]},′{url-to-sound}′)//播放

  pause()//暂停

  stop()//停止播放当前文件

  stopall()//停止播放所有文件

  start-time({numberofseconds})

  //从第几秒开始

  end-time({numberofseconds})

  //到第几秒结束

  setvol({percentagenumber-without″%″sign})

  //音量百分比控制

  fade-to({volumepercentyouwishtofadeto-withoutthe″%″sign})//削减音量到

  fade-from-to({volumepercentstartfade},{volumepercentendfade})

  //从某个音量值削减到某个音量值

  start-at-beginning()//从文件头开始

  stop-at-end()//到文件尾停止

  下面四个是状态测试函数

  isready()//准备状态测试

  isplaying()//播放状态测试

  ispaused()//暂停状态测试

  getvolume()//获取当前音量值

  3. 应用举例

  下面是一个包含netscape音频播放器所有五个元素的例子。考虑到有些用户没有声卡,本例中没有设置自动播放。读者可以根据自己的喜好结合鼠标事件将各个元素和测试函数都添加到图形按钮中。程序清单如下:

  〈 html〉

  〈 head〉

  〈 title〉音频播放器〈/title〉

  〈 scriptlanguage=javascript〉

  〈 !--writer:yuhaihe

  functionplaysound(){

  document.firstsound.play(true);

  }

  functionpausesound(){

  document.firstsound.pause();

  }

  functionstopsound(){

  document.firstsound.stop();

  }

  functionvolup(){

  currentvolume=document.firstsound.getvolume();

  newvolume=(currentvolume+10);

  if(document.firstsound.getvolume()==100){

  alert(″音量已经达到最大值″);

  }

  if(newvolume〈101){

  document.firstsound.setvol(newvolume); }

  else

  {

  if((newvolume〈=100)&&(newvolume〉90)){

  document.firstsound.setvol(100);

  } }

  }

  functionvoldown(){

  currentvolume=document.firstsound.getvolume();

  newvolume=(currentvolume-10);

  if(document.firstsound.getvolume()==0){

  alert(″音量已经达到最小值″);

  }

  if(newvolume〉0){

  document.firstsound.setvol(newvolume); }

  else {

   if((newvolume〉=0)&&(newvolume〈10)){ document.firstsound.setvol(0); } } }

  //endofjavascriptcode--〉

  〈 /script〉 〈 /head〉

  〈 body〉

  〈 embed src=″jn.mid″ hidden=true

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网