Created
April 3, 2019 13:23
-
-
Save dannyockilson/1954359c3cb73a3ece2432ddf5b377e9 to your computer and use it in GitHub Desktop.
Spotify Connect based Pass the Parcel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Spotify based Pass the Parcel</title> | |
</head> | |
<body> | |
<h1>Spotify based Pass the Parcel</h1> | |
<button id="resume">Start Passing that Parcel</button> | |
<script src="https://sdk.scdn.co/spotify-player.js"></script> | |
<script> | |
window.onSpotifyWebPlaybackSDKReady = () => { | |
const token = 'GET_YOUR_OWN_TOKEN'; // visit https://developer.spotify.com/documentation/web-playback-sdk/quick-start/ and click the get token button | |
const player = new Spotify.Player({ | |
name: 'Pass the Parcel player', | |
getOAuthToken: cb => { cb(token); } | |
}); | |
// Error handling | |
player.addListener('initialization_error', ({ message }) => { console.error(message); }); | |
player.addListener('authentication_error', ({ message }) => { console.error(message); }); | |
player.addListener('account_error', ({ message }) => { console.error(message); }); | |
player.addListener('playback_error', ({ message }) => { console.error(message); }); | |
// Connect to the player! | |
player.connect(); | |
document.getElementById('resume').addEventListener('click', (ev) => { | |
player.resume().then(() => { | |
console.log('starting playing again'); | |
// times 1000 to make into seconds, random number, max 20 seconds | |
const delay = (1000 * (Math.random() * 20)); | |
setTimeout(() => { | |
player.pause(); | |
}, delay); | |
}); | |
}); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment