Skip to content

Commit

Permalink
本地音乐和远程音乐使用同一个函数逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zhheo committed Nov 29, 2024
1 parent b4c1fac commit fc9c058
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
1 change: 1 addition & 0 deletions js/Meting.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class MetingJSElement extends HTMLElement {
this.appendChild(div)

this.aplayer = new APlayer(options)
window.ap = this.aplayer;

heo.setupMediaSessionHandlers(this.aplayer);
}
Expand Down
44 changes: 8 additions & 36 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var heo = {
for (let i = 0; i < lyrics.length; i++) {
if (lyrics[i] === event.target) {
// 获取当前播放器实例
const player = local ? ap : document.querySelector('meting-js').aplayer;
const player = ap;
// 使用播放器内部的歌词数据
if (player.lrc.current[i]) {
const time = player.lrc.current[i][0];
Expand Down Expand Up @@ -274,54 +274,34 @@ document.addEventListener("keydown", function (event) {
//暂停开启音乐
if (event.code === "Space") {
event.preventDefault();
if (local) {
ap.toggle();
} else {
document.querySelector('meting-js').aplayer.toggle();
}
ap.toggle();

};
//切换下一曲
if (event.keyCode === 39) {
event.preventDefault();
if (local) {
ap.skipForward();
} else {
document.querySelector('meting-js').aplayer.skipForward();
}
ap.skipForward();

};
//切换上一曲
if (event.keyCode === 37) {
event.preventDefault();
if (local) {
ap.skipBack();
} else {
document.querySelector('meting-js').aplayer.skipBack();
}
ap.skipBack();

}
//增加音量
if (event.keyCode === 38) {
if (volume <= 1) {
volume += 0.1;
if (local) {
ap.volume(volume, true);
} else {
document.querySelector('meting-js').aplayer.volume(volume, true);
}
ap.volume(volume, true);

}
}
//减小音量
if (event.keyCode === 40) {
if (volume >= 0) {
volume += -0.1;
if (local) {
ap.volume(volume, true);
} else {
document.querySelector('meting-js').aplayer.volume(volume, true);
}
ap.volume(volume, true);

}
}
Expand All @@ -330,17 +310,9 @@ document.addEventListener("keydown", function (event) {
// 监听窗口大小变化
window.addEventListener('resize', function() {
if (window.innerWidth > 768) {
if (local) {
ap.list.show();
} else {
document.querySelector('meting-js').aplayer.list.show();
}
ap.list.show();
} else {
if (local) {
ap.list.hide();
} else {
document.querySelector('meting-js').aplayer.list.hide();
}
ap.list.hide();
}

});
Expand Down
1 change: 1 addition & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
修复获取主题色问题
修复在移动端,首次进入总是自动打开播放列表
暂停时封面变小
现在本地音乐和远程音乐使用同一个函数逻辑

## 3.4
新增setupMediaSessionHandlers方法,响应 MediaSession 标准媒体交互 #23
Expand Down

0 comments on commit fc9c058

Please sign in to comment.