Last active
May 26, 2018 10:09
-
-
Save oskarrough/2761ebe5b42cfaea83ef587eb273f312 to your computer and use it in GitHub Desktop.
Standalone emergency player for Radio4000 --> http://jsbin.com/kiyudepuyo/edit?html,output
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
<div id="ytplayer"></div> |
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
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