xiangjiejie
on the load

导航

 
//触发音乐播放和暂停,解决ios不能自动播放音乐问题
var once=1;
(function(){
    $("body").bind('touchstart',function(){
        if(once==1){
        bmusic();
        }
    })
})()
function bmusic(){

    if (window.HTMLAudioElement) {
        try {
            var oAudio = document.getElementById('myaudio');
            var btn = document.getElementById('play');
            var audioURL = document.getElementById('audiofile');

            //Skip loading if current file hasn't changed.
            if (audioURL.value !== currentFile) {
                oAudio.src = audioURL.value;
                currentFile = audioURL.value;
            }

            // Tests the paused attribute and set state.
            if (oAudio.paused) {
                oAudio.play();
                once=0;
            }

        }
        catch (e) {
            // Fail silently but show in F12 developer tools console
            if(window.console && console.error("Error:" + e));
        }
    }
}

 

posted on 2015-05-14 14:58  xiangjiejie  阅读(752)  评论(0编辑  收藏  举报