JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<html>
<body>
<form id="queryForm">
<input id="query" type="text" value="kitten and acdc" />
<input id="search" type="submit" value="Search" />
</form>
<div id="video"></div>
<div id="audioTitle"></div>
<div id="audio"></div>
</body>
</html>
CSS
div {
font: 12px Arial;
}
#video {
padding-top: 30px;
}
#audio {
/* width: 1px;
height: 1px; */
opacity: 0;
filter: alpha(opacity=0);
}
JavaScript
video = function() { return $('#video').get()[0]; }
audio = function() { return $('#audio').get()[0]; }
window.onYouTubePlayerReady = function( id ) {
if ( id == 'video' )
video().addEventListener( 'onStateChange', 'onVideoEvent' );
else
audio().addEventListener( 'onStateChange', 'onAudioEvent' );
}
window.onVideoEvent = function(state) {
video().mute();
switch( state ) {
case 0: // ended
{
// video ended, we stop the audio as well
video().playVideo();
break;
}
case 1: // playing
{
audio().playVideo();
break;
}
case 2: // paused
case 3: // buffering
case 5: // cued
{
audio().pauseVideo();
break;
}
}
};
window.onAudioEvent = function(state) {
switch( state ) {
case 0: // ended
{
// audio ended, we start from the beginning again
audio().playVideo();
break;
}
}
};
$(document).ready(function(){
var url = 'http://gdata.youtube.com/feeds/api/videos?v=2&alt=json-in-script&&orderby=relevance&format=5';
var getSearchURL = function( keywords ) {
var searchURL = url;
searchURL += '&q=' + escape( keywords );
searchURL += '&callback=?';
return searchURL;
}
var embedVideo = function( url, id, width, height ) {
console.log(swfobject);
swfobject.embedSWF(
url + '&enablejsapi=1&playerapiid=' + id,
id,
width, height,
'10',
null,
{
autoplay: 1
},
{
allowfullscreen: true,
allowScriptAccess: 'always'
});
}
var playerURL = 'http://www.youtube.com/apiplayer?version=3';
embedVideo( playerURL, 'video', 420, 240 );
...