--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn LastFM Plug-in Demo</title>
+
+ <script src="../../popcorn.js"></script>
+ <script src="../../test/jquery.js"></script>
+ <script src="popcorn.lastfm.js"></script>
+ <script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var p = Popcorn('#video')
+ .play()
+ .lastfm({
+ start: 5, // seconds
+ end: 15, // seconds
+ artist: 'yacht',
+ target: 'lastfmdiv'
+ } )
+
+ .lastfm({
+ start: 20, // seconds
+ end: 45, // seconds
+ artist: 'Coldplay',
+ target: 'lastfmdiv'
+ } )
+ }, false);
+
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn LastFM Plug-in Demo</h1>
+ <p> Artist information for 'yacht' will appear at 5 seconds and disappear at 15 seconds.</p>
+ <p> Artist information for 'Coldplay' will appear at 20 seconds and disappear at 45 seconds.</p>
+ <div>
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ </div>
+ <div id="lastfmdiv" width="50%" height="50%">
+ </div>
+</body>
+</html>
--- /dev/null
+// PLUGIN: LASTFM
+
+(function (Popcorn) {
+
+ /**
+ * LastFM popcorn plug-in
+ * Appends information about a LastFM artist to an element on the page.
+ * Options parameter will need a start, end, target and artist.
+ * Start is the time that you want this plug-in to execute
+ * End is the time that you want this plug-in to stop executing
+ * Artist is the name of who's LastFM information you wish to show
+ * Target is the id of the document element that the images are
+ * appended to, this target element must exist on the DOM
+ *
+ * @param {Object} options
+ *
+ * Example:
+ var p = Popcorn('#video')
+ .lastfm({
+ start: 5, // seconds, mandatory
+ end: 15, // seconds, mandatory
+ artist: 'yacht', // mandatory
+ target: 'lastfmdiv' // mandatory
+ } )
+ *
+ */
+ Popcorn.plugin( "lastfm" , {
+
+ manifest: {
+ about:{
+ name: "Popcorn LastFM Plugin",
+ version: "0.1",
+ author: "Steven Weerdenburg",
+ website: "http://sweerdenburg.wordpress.com/"
+ },
+ options:{
+ start : {elem:'input', type:'text', label:'In'},
+ end : {elem:'input', type:'text', label:'Out'},
+ target : 'lastfm-container',
+ artist : {elem:'input', type:'text', label:'Artist'}
+ }
+ },
+
+ _setup: function( options ) {
+ options.container = document.createElement( 'div' );
+ options.container.style.display = "none";
+ if ( document.getElementById( options.target ) ) {
+ document.getElementById( options.target ).appendChild( options.container );
+ }
+
+ var htmlString = "";;
+ $.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ options.artist +"&api_key=30ac38340e8be75f9268727cb4526b3d&format=json&callback=?",
+ function(data){
+ htmlString += '<h3>'+data.artist.name+'</h3>';
+ htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
+ htmlString += '<p>'+ data.artist.bio.summary +'</p>';
+ htmlString += '<hr /><p><h4>Tags</h4><ul>';
+ $.each(data.artist.tags.tag, function(i,val) {
+ htmlString += '<li><a href="'+ this.url +'">'+ this.name +'</a></li>';
+ });
+ htmlString += '</ul></p>';
+ htmlString += '<hr /><p><h4>Similar</h4><ul>';
+ $.each(data.artist.similar.artist, function(i,val) {
+ htmlString += '<li><a href="'+ this.url +'">'+ this.name +'</a></li>';
+ });
+ htmlString += '</ul></p>';
+ options.container.innerHTML = htmlString;
+ }
+ );
+ },
+ /**
+ * @member LastFM
+ * The start function will be executed when the currentTime
+ * of the video reaches the start time provided by the
+ * options variable
+ */
+ start: function( event, options ) {
+ options.container.style.display = "inline";
+ },
+ /**
+ * @member LastFM
+ * The end function will be executed when the currentTime
+ * of the video reaches the end time provided by the
+ * options variable
+ */
+ end: function( event, options ) {
+ options.container.style.display = "none";
+ }
+ });
+
+})( Popcorn );
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn API</title>
+ <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+ <script src="../../test/qunit/qunit.js"></script>
+ <!--
+ do not move - this must be called immediately prior to
+ popcorn-api-draft.js
+ -->
+
+ <script src="../../popcorn.js"></script>
+ <script src="../../test/jquery.js"></script>
+ <script src="popcorn.lastfm.js"></script>
+
+ <script src="popcorn.lastfm.unit.js"></script>
+</head>
+<body>
+
+ <h1 id="qunit-header">Popcorn LastFM Plugin</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"> </div>
+
+ <video id='video'
+ controls
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ <div id="lastfmdiv"></div>
+</body>
+</html>
--- /dev/null
+test("Popcorn LastFM Plugin", function () {
+
+ var popped = Popcorn("#video"),
+ expects = 5,
+ count = 0,
+ interval,
+ interval2,
+ lastfmdiv = document.getElementById('lastfmdiv');
+
+ expect( expects );
+
+ function plus() {
+ if ( ++count === expects) {
+ start();
+ }
+ }
+
+ stop();
+
+ ok('lastfm' in popped, "lastfm is a method of the popped instance");
+ plus();
+
+ equals ( lastfmdiv.innerHTML, "", "initially, there is nothing inside the lastfmdiv" );
+ plus();
+
+ popped.lastfm({
+ start: 1, // seconds
+ end: 3, // seconds
+ artist: 'yacht',
+ target: 'lastfmdiv'
+ } );
+
+ interval = setInterval( function() {
+ if( popped.currentTime() > 1 && popped.currentTime() < 3 ) {
+ ok( /display: inline;/.test( lastfmdiv.innerHTML ), "Div contents are displayed" );
+ plus();
+ ok( /img/.test( lastfmdiv.innerHTML ), "An image exists" );
+ plus();
+ clearInterval( interval );
+ }
+ }, 500);
+
+ interval2 = setInterval( function() {
+ if( popped.currentTime() > 3 ) {
+ ok( /display: none;/.test( lastfmdiv.innerHTML ), "Div contents are hidden again" );
+ plus();
+ clearInterval( interval2 );
+ }
+ }, 500);
+ popped.volume(0);
+ popped.play();
+
+});