【发布时间】:2021-10-05 22:05:18
【问题描述】:
我正在关注播放 SDK 快速入门链接 here,但由于某种原因,我无法播放音乐。
这是我的代码
<!DOCTYPE html>
<html>
<head>
<title>Spotify Web Playback SDK Quick Start</title>
</head>
<body>
<button id="togglePlay">Toggle Play</button>
<h1>Spotify Web Playback SDK Quick Start</h1>
<script src="https://sdk.scdn.co/spotify-player.js"></script>
<script>
window.onSpotifyWebPlaybackSDKReady = () => {
const token ='mytokenhere';
const player = new Spotify.Player({
name: "Web Playback SDK Quick Start Player",
getOAuthToken: (cb) => {
cb(token);
},
volume: 0.5,
});
// Ready
player.addListener("ready", ({ device_id }) => {
console.log("Ready with Device ID", device_id);
});
// Not Ready
player.addListener("not_ready", ({ device_id }) => {
console.log("Device ID has gone offline", device_id);
});
player.addListener("initialization_error", ({ message }) => {
console.error(message);
});
player.addListener("authentication_error", ({ message }) => {
console.error(message);
});
player.addListener("account_error", ({ message }) => {
console.error(message);
});
document.getElementById("togglePlay").onclick = function () {
player.togglePlay();
};
player.connect();
};
</script>
</body>
</html>
我在控制台中看到播放器已准备就绪,但我在任何地方都看不到播放器,也听不到音乐。我错过了什么吗?
【问题讨论】:
标签: javascript spotify