Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios-音乐自动播放问题 #27

Open
wohaofang opened this issue Jul 31, 2020 · 0 comments
Open

ios-音乐自动播放问题 #27

wohaofang opened this issue Jul 31, 2020 · 0 comments

Comments

@wohaofang
Copy link
Owner

ios

方法一

//第一步:首先加载一个微信JS-SDK
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
//第2步:写一些配置
<script>
function autoPlayAudio() {
        wx.config({
            // 配置信息, 即使不正确也能使用 wx.ready
            debug: false,
            appId: '',
            timestamp: 1,
            nonceStr: '',
            signature: '',
            jsApiList: []
        });
        wx.ready(function() {
            var globalAudio=document.getElementById("audio标签id");
            globalAudio.play();
        });
};
// 解决ios音乐不自动播放的问题
autoPlayAudio();
</script>

方法二

这个是监听touch事件  开启播放
 // function audioAutoPlay(id){
          //   var audio = document.getElementById(id),
          //       play = function(){
          //       audio.play();
          //       document.removeEventListener("touchstart",play, false);
          //   };
          //   audio.play();
          //   document.addEventListener("WeixinJSBridgeReady", function () {
          //       play();
          //   }, false);
          //   document.addEventListener("touchstart",play, false);
          // }
  // audioAutoPlay('audio');
通过点击进行load

安卓

          var myAudio = document.getElementById('audio')
          myAudio.pause()  播放
          myAudio.play()  暂停
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant