码迷,mamicode.com
首页 > Web开发 > 详细

JS 播放声音

时间:2014-07-23 12:55:56      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   width   io   

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 播放声音,布布扣,bubuko.com

JS 播放声音

标签:style   blog   color   os   width   io   

原文地址:http://www.cnblogs.com/allvie/p/3862562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!