<audio id="music1" preoload autoplay> <source src="./all-01.mp3" type="audio/mp3" /> </audio>
<script src="./pixi.min.js"></script> <script src="./pixi-sound.js"></script>
<script>// 播放音乐 function audioAutoPlay (id) { let audio = document.getElementById(id) if (window.WeixinJSBridge) { WeixinJSBridge.invoke( 'getNetworkType', {}, function (e) { audio.play() }, false ) } else { document.addEventListener( 'touchstart', function () { WeixinJSBridge.invoke('getNetworkType', {}, function (e) { audio.play() }) }, false ) } } // 检查版本
function CheckIsAndroid () { var browser = { versions: (function () { var u = navigator.userAgent return { //移动终端浏览器版本信息 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 //u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器 iPad: u.indexOf('iPad') > -1 //是否iPad } })() } if (browser.versions.android) return true return false } window.sound_1 = PIXI.sound.Sound.from({ // 用pixi-sound载入音乐,用于安卓 url: './all-01.mp3', loop: false }) if (CheckIsAndroid()) { window.sound_1.play() }else {audioAutoPlay('music1')
}
</script>
js 文件
链接:https://pan.baidu.com/s/15bHHcqcQTuTfWBSeFK_CMg
提取码:z1cj