Skip to content
Browse files

It only bloody works

  • Loading branch information...
1 parent c9ebe8d commit 644abaf4baa0fc040b7795e5aebb2f60ae943c1b @NeilCrosby NeilCrosby committed Dec 14, 2008
Showing with 83 additions and 8 deletions.
  1. +83 −8 index.php
View
91 index.php
@@ -25,13 +25,88 @@
$lastGenius = new LastGenius();
$playlist = $lastGenius->getPlaylist($track, $artist, $numTracksRequired);
-echo '<ol>';
-foreach ($playlist as $item) {
- echo "<li>{$item->artist->name} - {$item->name} - {$item->match}</li>\n";
-}
-echo '</ol>';
-
$taken = time() - $start;
-echo "<p>Took $taken seconds</p>";
-?>
+?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Last Genius</title>
+ <style>
+ body {
+ }
+ </style>
+</head>
+<body>
+<?php
+ echo '<ol id="playlist">';
+ foreach ($playlist as $item) {
+ echo "<li><a href=\"{$item->url}\">{$item->artist->name} - {$item->name} - <span class=\"duration\">{$item->duration}</span></a></li>\n";
+ }
+ echo '</ol>';
+
+ echo "<p>Took $taken seconds</p>";
+?>
+
+<iframe id="music-player1" src="<?php echo $playlist[0]->url; ?>?autostart"></iframe>
+<iframe id="music-player2"></iframe>
+<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
+<script>
+YAHOO.namespace('tct.lastGenius');
+
+YAHOO.tct.lastGenius = function () {
+
+ var yue = YAHOO.util.Event,
+ yud = YAHOO.util.Dom;
+
+ //the returned object here will become YAHOO.myProject.myModule:
+ return {
+
+ init: function () {
+ console.log('init');
+ YAHOO.util.Event.onContentReady('music-player1', this.loadNewTrack, 0);
+ },
+
+ loadNewTrack: function(trackNum) {
+ var id = ( trackNum / 2 === parseInt(trackNum / 2, 10) ) ? 1 : 2;
+ console.log(trackNum + ' ' + id);
+
+ var listEl = yud.get('playlist');
+ var listEls = listEl.getElementsByTagName('li');
+ console.log(listEls.length);
+ if (trackNum >= listEls.length) {
+ return;
+ }
+
+ var temp = listEls[trackNum].getElementsByTagName('a');
+ var url = temp[0].href;
+ console.log(url);
+
+ var player = document.getElementById('music-player'+id);
+ player.src = url + '?autostart';
+
+ setTimeout( "YAHOO.tct.lastGenius.destroyTrack(" + (trackNum - 1) + ")", 2000);
+
+ setTimeout( "YAHOO.tct.lastGenius.loadNewTrack(" + (trackNum + 1) + ")", 30000);
+ },
+
+ destroyTrack: function(trackNum) {
+ console.log('destroying');
+ var id = ( trackNum / 2 === parseInt(trackNum / 2, 10) ) ? 1 : 2;
+
+ var player = document.getElementById('music-player'+id);
+ player.src = '';
+ }
+
+
+
+ };
+}();
+
+YAHOO.tct.lastGenius.init();
+
+</script>
+
+</body>
+<html>

0 comments on commit 644abaf

Please sign in to comment.
Something went wrong with that request. Please try again.