JSFiddle - React, Tailwind, and code Playground
by danmana
HTML
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. 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);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 's9shPouRWCs',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
var phonemes = {
a: {start:155.25,duration:300},
t: {start:155.75,duration:200},
ch: {start:156.2,duration:300},
sh: {start:156.83,duration:300},
f: {start:157.2,duration:300},
s: {start:172.25,duration:200},
p: {start:172.80,duration:200},
e: {start:173.45,duration:280},
ai: {start:215.7,duration:350},
o: {start:216.25,duration:300},
u: {start:216.75,duration:300}
};
var beatbox = ['a','t', 'ch', 'sh'];
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false, timeoutId, playing;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !playing && beatbox.length) {
playing=true;
nextBeat();
}
}
function toPhonemes(str)...