首页 > 代码库 > JS 播放声音
JS 播放声音
var shakesound;function initsound() { soundOn = true; shakesound = document.getElementById(‘shakesound‘);}var soundOn = false;var audioTracks = [ // 8 tracks is more than enough new Audio(), new Audio(), new Audio(), new Audio(), new Audio(), new Audio(), new Audio(), new Audio()];function soundIsPlaying(sound) { return !sound.ended && sound.currentTime > 0;}function playSound(sound) { if (!sound) return; var track, index; sound.play(); if (soundOn) { if (!soundIsPlaying(sound)) { sound.play(); } else { for (i = 0; index < audioTracks.length; ++index) { track = audioTracks[index]; if (!soundIsPlaying(track)) { track.src = sound.currentSrc; track.load(); track.volume = sound.volume; track.play(); break; } } } }}
<audio id=‘shakesound‘ width="0" height="0" preload="auto" controls="controls" style="z-index: -100; width: 0; height: 0; position: absolute;"> <source src=http://www.mamicode.com/‘sounds/shake.mp3‘ type=‘audio/mp3‘>>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。