Skip to content

Commit 0e4e3f6

Browse files
committed
✨ feat(protocol): 支持最基础的歌曲播放
1 parent a6d81bd commit 0e4e3f6

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/utils/protocal.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import { songDetail } from "@/api/song";
2+
import { formatSongsList } from "@/utils/format";
3+
import { usePlayer } from "@/utils/player";
4+
15
class OrpheusData {
2-
constructor(type: string, id: string, cmd: string) {
6+
constructor(type: string, id: number, cmd: string) {
37
this.type = type;
48
this.id = id;
59
this.cmd = cmd;
610
}
711

8-
type: string = "";
9-
id: string = "";
10-
cmd: string = "";
12+
type: string;
13+
id: number;
14+
cmd: string;
1115
}
1216

1317
export const handleProtocolUrl = (url: string) => {
@@ -22,12 +26,19 @@ export const handleProtocolUrl = (url: string) => {
2226

2327

2428

25-
export const handleOpenOrpheus = (url: string) => {
29+
export const handleOpenOrpheus = async (url: string) => {
2630
const data = parseOrpheus(url);
2731
if (!data) return;
2832
console.log("🚀 Open Orpheus:", data);
2933

30-
// TODO 处理
34+
if (data.cmd === "play" && data.type === "song") {
35+
const player = usePlayer();
36+
const result = await songDetail(data.id);
37+
const song = formatSongsList(result.songs)[0];
38+
player.addNextSong(song, true);
39+
} else {
40+
console.log("❌ Unsupported Command or Type:", data);
41+
}
3142
};
3243

3344
const parseOrpheus = (url: string): OrpheusData | undefined => {

0 commit comments

Comments
 (0)