Skip to content

Instantly share code, notes, and snippets.

@oskarrough
Last active May 26, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskarrough/2761ebe5b42cfaea83ef587eb273f312 to your computer and use it in GitHub Desktop.
Save oskarrough/2761ebe5b42cfaea83ef587eb273f312 to your computer and use it in GitHub Desktop.
Standalone emergency player for Radio4000 --> http://jsbin.com/kiyudepuyo/edit?html,output
<div id="ytplayer"></div>
var player
function playRadio(slug) {
var endpoint = `https://api.radio4000.com/backup?slug=${slug}`
fetch(endpoint)
.then(res => res.json())
.then(backup => {
var playlist = backup.tracks.map(t => t.ytid)
player.loadPlaylist({playlist})
})
}
// The API will call this function when the video player is ready.
function onPlayerReady(event) {
playRadio('200ok')
}
// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script')
tag.src = 'https://www.youtube.com/iframe_api'
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
window.onYouTubeIframeAPIReady = function () {
player = new YT.Player('ytplayer', {
height: '390',
width: '640',
events: {
'onReady': onPlayerReady
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment