超级推荐用这个大佬写的aplayer插件
地址:https://github.com/MoePlayer/APlayer-Typecho 然后在预加载重载函数里写上
代码语言:javascript复制loadMeting();
即可
如果遇到切换页面音乐不停止的问题,再重载函数里再补充这条语句
代码语言:javascript复制if (typeof aplayers !== 'undefined'){
for (var i = 0; i < aplayers.length; i ) {
try {aplayers[i].destroy()} catch(e){}
}
}
↓以下文章内容已弃用
APlayer Typecho插件
https://github.com/FaithPatrick/APlayer-Typecho-Plugin
instantclick 3.0.1版兼容
方法来自https://muguang.me/php/typecho-theme-apollo.html
将预加载的执行代码
代码语言:javascript复制<script data-no-instant>
InstantClick.init();
</script>
改为
代码语言:javascript复制 <script data-no-instant>
if (!window.audios) {
audios = [];
for (var i = 0; i < APlayers.length; i ) {
audios[i] = APlayers[i].audio;
}
}
InstantClick.on('change', function (isInitialLoad) {
for (var i = 0; i < APlayers.length; i ) {
audios.push(APlayers[i].audio);
}
for(var i = 0; i < audios.length; i ) {if(audios[i]){audios[i].pause()}};
});
InstantClick.init();
</script>
<script>var APlayerOptions = [];</script>//如果无效果尝试删掉这行
instantclick 3.1.0版兼容[不完美]
这个是我参考上边的瞎弄弄出来的,虽然完全看不懂QAQ。。。
打开插件的plugin.php
将里面的
<script>
var len = APlayerOptions.length;
for(var i=0;i<len;i ){
if(document.getElementById('player' APlayerOptions[i]['id'])) {
APlayers[i] = new APlayer({
element: document.getElementById('player' APlayerOptions[i]['id']),
narrow: false,
preload: APlayerOptions[i]['preload'],
mutex: APlayerOptions[i]['mutex'],
autoplay: APlayerOptions[i]['autoplay'],
showlrc: APlayerOptions[i]['showlrc'],
music: APlayerOptions[i]['music'],
theme: APlayerOptions[i]['theme']
});
//APlayers[i].init();
}
}
</script>
改为
代码语言:javascript复制<script data-no-instant>//就是这里有修改,其他都没动
var len = APlayerOptions.length;
for(var i=0;i<len;i ){
if(document.getElementById('player' APlayerOptions[i]['id'])) {
APlayers[i] = new APlayer({
element: document.getElementById('player' APlayerOptions[i]['id']),
narrow: false,
preload: APlayerOptions[i]['preload'],
mutex: APlayerOptions[i]['mutex'],
autoplay: APlayerOptions[i]['autoplay'],
showlrc: APlayerOptions[i]['showlrc'],
music: APlayerOptions[i]['music'],
theme: APlayerOptions[i]['theme']
});
//APlayers[i].init();
}
}
</script>
将预加载的执行代码
代码语言:javascript复制<script data-no-instant>
InstantClick.init();
</script>
改为
代码语言:javascript复制 <script data-no-instant>
if (!window.audios) {
audios = [];
for (var i = 0; i < APlayers.length; i ) {
audios[i] = APlayers[i].audio;
}
}
InstantClick.on('change', function(isInitialLoad) {
if (isInitialLoad === false) {
var len = APlayerOptions.length;
for(var i=0;i<len;i ){
if(document.getElementById('player' APlayerOptions[i]['id'])) {
APlayers[i] = new APlayer({
element: document.getElementById('player' APlayerOptions[i]['id']),
narrow: false,
preload: APlayerOptions[i]['preload'],
mutex: APlayerOptions[i]['mutex'],
autoplay: APlayerOptions[i]['autoplay'],
showlrc: APlayerOptions[i]['showlrc'],
music: APlayerOptions[i]['music'],
theme: APlayerOptions[i]['theme']
});
//APlayers[i].init();
}
}
for (var i = 0; i < APlayers.length; i ) {audios.push(APlayers[i].audio);}
for(var i = 0; i < audios.length; i ) {if(audios[i]){audios[i].pause()}};
}
});
InstantClick.init();</script>