`

JS播放声音

    博客分类:
  • JS
阅读更多

1. 导入相关的JS文件

<script language="javascript" src="script/LodopFuncs.js"></script>

2. 在JS文件写入代码

soundManager.setup({
     url: 'swf/', //swf文件夹的位置
     onready: function() {
        soundManager.createSound({
          id: 'test_sound0',
          autoLoad: true,
          autoPlay: false,
          url: mp3/1.mp3' //mp3文件的位置(IE只能播放MP3格式)
        });
     }
   });

3.播放声音

soundManager.play('test_sound0');

// 下面代码是调用关闭声音方法,有时可能等不到声音播放完毕,就需要停止

soundManager.stop('test_sound0');

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics