Skip to content

Commit

Permalink
first checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbot committed Dec 18, 2011
0 parents commit d1d3f3e
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 0 deletions.
23 changes: 23 additions & 0 deletions BbBuddha.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body {
margin: 0;
text-align: center;
}

#container {
margin: 0 auto;
width: 880px;
}

#controls {
font-size: 16px;
margin: 10px 0px;
text-align: left;
}

.ytobj {
float: left;
height: 182px;
margin: 0;
padding:0;
width: 220px;
}
134 changes: 134 additions & 0 deletions BbBuddha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
//Copyright(c)2009 tikirobot.net Software license AGPL version 3.
//inspired by the magical http://inbflat.net

// BbBuddha()
//______________________________________________________________________________
function BbBuddha() {

this.timer = null;
this.numPlaying = 0;
this.numLoaded = 0;
this.maxPlaying = 6;
this.isPlaying = false;
}

// init()
//______________________________________________________________________________
BbBuddha.prototype.init = function() {
//console.log('init BbBuddha');

for (var i=0; i<12; i++) {
$('#myytplayer'+i).get(0).addEventListener('onStateChange', 'stateChange');
}

$('#loading').hide();
$('#playButton').show();
this.start();
}

// start()
//______________________________________________________________________________
BbBuddha.prototype.start = function() {
var self = this;
this.startVideo();
this.timer = setInterval(function(){self.startVideo()}, 5000);
this.isPlaying = true;
$('#playButton').text('Stop AutoPlay')
}

// toggle()
//______________________________________________________________________________
BbBuddha.prototype.toggle = function() {
if (this.isPlaying) {
this.stop();
} else {
this.start();
}
}

// stop()
//______________________________________________________________________________
BbBuddha.prototype.stop = function() {
clearInterval(this.timer);
for (var i=0; i<12; i++) {
$('#myytplayer'+i).get(0).pauseVideo();
}
this.isPlaying = false;
this.numPlaying = 0;
$('#playButton').text('Start AutoPlay')
}


// startVideo()
//______________________________________________________________________________
BbBuddha.prototype.startVideo = function() {
if (this.numPlaying >= this.maxPlaying) {
//console.log('numPlaying = ' + this.numPlaying + ', returning');
return;
}
var vidNum =Math.floor(Math.random()*12);
var player = $('#myytplayer'+vidNum).get(0);
var state = player.getPlayerState(); //state 1 == playing

if (8 == vidNum) { //special case for spoken word
// I love the spoken word piece, but if I leave this
// playing all day, I hear it too often
var rand = Math.random();
if (rand > 0.25) return;
}

if (1 != state) {
var vol =Math.floor(Math.random()*100);
player.setVolume(vol);
player.playVideo();
this.numPlaying++;
//console.log('startVideo ' + vidNum + ' with vol = ' + vol);
}
}



var buddha = new BbBuddha();

/////Callbacks:

// onYouTubePlayerReady()
//______________________________________________________________________________
function onYouTubePlayerReady(playerid) {
buddha.numLoaded++;
$('#numLoaded').text(buddha.numLoaded);
//console.log(playerid + ' is ready');

if (12 == buddha.numLoaded) {
buddha.init();
}
}

// stateChange()
//______________________________________________________________________________
// States:
// -1: unstarted
// 0: ended
// 1: playing
// 2: stopped
// 3: buffering
// 5: video cued
function stateChange(newState) {

if (0 == newState) { //some video stopped playing, update numPlaying
var numPlaying = 0;
var i;
for (i=0; i<12; i++) {
var player = $('#myytplayer'+i).get(0);
var state = player.getPlayerState(); //state 1 == playing
if (1 == state) {
numPlaying++;
}
}


buddha.numPlaying = numPlaying;

//console.log('numPlaying = ' + numPlaying);
}
}
118 changes: 118 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<html>
<head>
<title>Bb Buddha Machine</title>
<link rel="stylesheet" href="BbBuddha.css" type="text/css" media="screen" />
<script src="jquery-1.3.2.min.js"></script>
<script src="swfobject.js"></script>
<script src="BbBuddha.js"></script>
</head>
<body>

<div id="container">

<div>
[A <a href="http://code.google.com/apis/youtube/js_api_reference.html">javascript</a> <a href="http://en.wikipedia.org/wiki/Buddha_machine">Buddha Machine</a> based on the magical <b><a href="http://inbflat.net">In B flat</a></b>] [<a href="BbBuddha.js">code</a>] [<a href="http://en.wikipedia.org/wiki/In_C">In C</a>]
</div>

<div id="controls">
<span id="loading">loading <span id="numLoaded">0</span>/12</span>
<button id="playButton" onclick="buddha.toggle()" style="display:none;">Stop AutoPlay</button>
</div>


<div id="ytplayer0" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer1" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer2" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer3" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer4" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer5" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer6" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer7" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer8" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer9" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer10" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<div id="ytplayer11" class="vids">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>

</div>

<script type="text/javascript">

var params = { allowScriptAccess: "always" };

swfobject.embedSWF("http://www.youtube.com/v/gqtYwouDzl4&enablejsapi=1&playerapiid=ytplayer0",
"ytplayer0", "220", "182", "8", null, null, params, {"id": "myytplayer0", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/xevYHoXWX0Y&enablejsapi=1&playerapiid=ytplayer1",
"ytplayer1", "220", "182", "8", null, null, params, {"id": "myytplayer1", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/JLn--qQSNN8&enablejsapi=1&playerapiid=ytplayer2",
"ytplayer2", "220", "182", "8", null, null, params, {"id": "myytplayer2", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/2aJPXS-QRIc&enablejsapi=1&playerapiid=ytplayer3",
"ytplayer3", "220", "182", "8", null, null, params, {"id": "myytplayer3", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/JyTRnVQS8PA&enablejsapi=1&playerapiid=ytplayer4",
"ytplayer4", "220", "182", "8", null, null, params, {"id": "myytplayer4", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/PmKWkiDAm5k&enablejsapi=1&playerapiid=ytplayer5",
"ytplayer5", "220", "182", "8", null, null, params, {"id": "myytplayer5", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/9s7X8PgOf3A&enablejsapi=1&playerapiid=ytplayer6",
"ytplayer6", "220", "182", "8", null, null, params, {"id": "myytplayer6", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/ztv4rvZ8CaI&enablejsapi=1&playerapiid=ytplayer7",
"ytplayer7", "220", "182", "8", null, null, params, {"id": "myytplayer7", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/w5IERp2OdJs&enablejsapi=1&playerapiid=ytplayer8",
"ytplayer8", "220", "182", "8", null, null, params, {"id": "myytplayer8", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/WMLvKpiG3RA&enablejsapi=1&playerapiid=ytplayer9",
"ytplayer9", "220", "182", "8", null, null, params, {"id": "myytplayer9", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/E-DrBhawMfI&hl&enablejsapi=1&playerapiid=ytplayer10",
"ytplayer10", "220", "182", "8", null, null, params, {"id": "myytplayer10", "class": "ytobj"});

swfobject.embedSWF("http://www.youtube.com/v/b7F5c8hjiYc&enablejsapi=1&playerapiid=ytplayer11",
"ytplayer11", "220", "182", "8", null, null, params, {"id": "myytplayer11", "class": "ytobj"});

</script>


</body>
</html>

0 comments on commit d1d3f3e

Please sign in to comment.