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

新增自动播放背景音乐功能 #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<title>鱼了个鱼</title>
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({id: "JonPnywkOzKkLXdw",ck: "JonPnywkOzKkLXdw"})</script>
<script type="text/javascript" src="/src/assets/musics/auto-music.js"></script>
<!-- 微信上进入页面是会自动播放的 其它浏览器打开需要触碰一下页面任意地方才会播放 -->
<div style="display: block;z-index:999999;">
<audio preload="auto" autoplay="autoplay" id="audio" src="/src/assets/musics/1.mp3" loop="loop"></audio>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vercel 国外部署访问本来就有点慢,音乐可能会影响资源的加载

</div>
</head>
<body>
<div id="app"></div>
Expand Down
Binary file added src/assets/musics/1.mp3
Binary file not shown.
Binary file added src/assets/musics/2.mp3
Binary file not shown.
24 changes: 24 additions & 0 deletions src/assets/musics/auto-music.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//--创建页面监听,等待微信端页面加载完毕 触发音频播放
document.addEventListener("DOMContentLoaded", function () {
function audioAutoPlay() {
var audio = document.getElementById("audio");
audio.play();
document.addEventListener(
"WeixinJSBridgeReady",
function () {
audio.play();
},
false
);
}
audioAutoPlay();
});

//--创建触摸监听,当浏览器打开页面时,触摸屏幕触发事件,进行音频播放
document.addEventListener("touchstart", function () {
function audioAutoPlay() {
var audio = document.getElementById("audio");
audio.play();
}
audioAutoPlay();
});