首页 > 移动平台 > 详细

苹果手机端触屏自动播放音乐

时间:2015-05-14 16:18:25      阅读:204      评论:0      收藏:0      [点我收藏+]
//触发音乐播放和暂停,解决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));
        }
    }
}

 

苹果手机端触屏自动播放音乐

原文:http://www.cnblogs.com/light-j/p/4503366.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!