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=‘sounds/shake.mp3‘ type=‘audio/mp3‘>
            <source src=‘sounds/shake.ogg‘ type=‘audio/ogg‘>
            <source src=‘sounds/shake.wav‘ type=‘audio/wav‘>
        </audio>

JS 播放声音,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。