From: stevenaw Date: Wed, 20 Apr 2011 16:50:17 +0000 (-0400) Subject: [#380] API signature updated. Test timeout increassed X-Git-Tag: v0.5~1^2~3 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=766ef80abccc137c7d2bf2f07242b48e547fc35e;p=popcorn-js.git [#380] API signature updated. Test timeout increassed --- diff --git a/players/soundcloud/popcorn.soundcloud.html b/players/soundcloud/popcorn.soundcloud.html index a575711..80d0ed3 100644 --- a/players/soundcloud/popcorn.soundcloud.html +++ b/players/soundcloud/popcorn.soundcloud.html @@ -52,7 +52,8 @@ popcorn.mute(); }, false); - popcorn = Popcorn( Popcorn.soundcloud( "media_1", { + popcorn = Popcorn( Popcorn.soundcloud({ + target: "media_1", width: "50%", /* This demo contains an api key used for retrieving comments from Soundcloud's API diff --git a/players/soundcloud/popcorn.soundcloud.js b/players/soundcloud/popcorn.soundcloud.js index 23eaa25..724895d 100644 --- a/players/soundcloud/popcorn.soundcloud.js +++ b/players/soundcloud/popcorn.soundcloud.js @@ -5,43 +5,48 @@ * This player adds enables Popcorn.js to handle Soundcloud audio. It does so by masking an embedded Soundcloud Flash object * as a video and implementing the HTML5 Media Element interface. * - * You can specify the video in four ways: - * 1. Use the embed code path supplied by Soundcloud as a div's data-src attribute, and pass the div id into a new Popcorn.soundcloud object + * You can configure the video source and dimensions in two ways: + * 1. Use the embed code path supplied by Soundcloud the id of the desired location into a new Popcorn.soundcloud object. + * Width and height can be configured throughh CSS. * - *
+ *
* * - * 2. Pass the div id and the embed code path supplied by Soundcloud into a new Popcorn.soundcloud object + * 2. Width and height may also be configured directly with the player. This will override any CSS. * - *
- * + *
+ * * - * The player can be further configured when it is created by adding other attrributes. A complete list (all optional): + * The player can be further configured to integrate with the SoundCloud API: * * var popcorn = Popcorn( Popcorn.soundcloud( "player_1", { - * src: "http://soundcloud.com/forss/flickermood", // The Soundcloud track to play - * width: "100%", // The width for the player. May also be as '##px' - * height: "81px", // The height for the player. May also be as '###%' - * api_key: "abcdefsdfsdf", // Soundcloud API key, required for retrieving comments - * commentdiv: "divId_for_output", // Div Id for outputting comments - * commentformat: function( comment ) {} // Function to format a comment. Returns HTML string + * target: "player_1", // Required, the location to place the player + * src: "http://soundcloud.com/forss/flickermood", // Required, the Soundcloud track to play + * width: "100%", // Optional, the width for the player. May also be as '##px' + * // Defaults to the maximum possible width + * height: "81px", // Optional, the height for the player. May also be as '###%' + * // Defaults to 81px + * api_key: "abcdefsdfsdf", // Optional, the Soundcloud API key, required for retrieving comments + * commentdiv: "divId_for_output", // Optional, the Div Id for outputting comments + * commentformat: function( comment ) {} // Optional, a function to format a comment. Returns HTML string * })); * - * Height, width and track source may be specified in other ways. Height and width may be throughh CSS or inline on the container - * div's attributes (data-height, data-width). Track source may be specified on the container element as an attribute (data-src). - * See above example. Values may be overridden if height, width or souurce are specified in moree than one way. - * The hierarchy is: - * - * constructor -> inline -> CSS - * * Comments are retrieved from Soundcloud when the player is registered with Popcorn by calling the registerWithPopcorn() * function. For this to work, the api_key and commentdiv attributes must be set. Comments are output by default similar to * how Soundcloud formats them in-player, but a custom formatting function may be supplied. It receives a comment object and @@ -322,14 +327,15 @@ }); }); - Popcorn.soundcloud = function( containerId, options ) { - return new Popcorn.soundcloud.init( containerId, options ); + Popcorn.soundcloud = function( options ) { + return new Popcorn.soundcloud.init( options ); }; // A constructor, but we need to wrap it to allow for "static" functions Popcorn.soundcloud.init = (function() { - function pullFromContainer( that, options ) { - var container = that._container, + function pullFromContainer( that ) { + var options = that._options, + container = that._container, bounds = container.getBoundingClientRect(), tmp, undef; @@ -341,7 +347,7 @@ that.width = options.width || getStyle( container, "width" ) || "100%"; that.height = options.height || getStyle( container, "height" ) || "81px"; that.src = options.src; - that.autoplay = container.getAttribute( "data-autoplay" ) || undef; + that.autoplay = options.autoplay; if ( parseFloat( that.height, 10 ) !== 81 ) { that.height = "81px"; @@ -369,21 +375,20 @@ } // If container id is not supplied, assumed to be same as player id - var ctor = function ( containerId, options ) { - if ( !containerId ) { + var ctor = function ( options ) { + if ( !options || !options.target ) { throw "Must supply an id!"; } else if ( /file/.test( location.protocol ) ) { throw "Must run from a web server!"; } - var container = this._container = document.getElementById( containerId ); + var containerId = options.target, + container = this._container = document.getElementById( containerId ); if ( !container ) { throw "Could not find that container in the DOM!"; } - options = options || {}; - options.commentformat = options.commentformat || formatComment this._mediaId = 0; @@ -394,9 +399,7 @@ this._comments = []; this._popcorn; - this._options.src = options.src || container.getAttribute( "data-src" ); - - pullFromContainer( this, this._options ); + pullFromContainer( this ); this.duration = 0; this.volume = 1; diff --git a/players/soundcloud/popcorn.soundcloud.unit.js b/players/soundcloud/popcorn.soundcloud.unit.js index 53b107c..a60aaae 100644 --- a/players/soundcloud/popcorn.soundcloud.unit.js +++ b/players/soundcloud/popcorn.soundcloud.unit.js @@ -3,7 +3,8 @@ test( "API", function () { var expects = 0, count = 0, - player = Popcorn.soundcloud( "player_1", { + player = Popcorn.soundcloud({ + target: "player_1", src: "http://soundcloud.com/forss/flickermood" }), members = { @@ -101,10 +102,12 @@ test( "Default Attribute Functionality", function () { expect( expects ); stop( 10000 ); - playerDefault = Popcorn.soundcloud( "player_2", { + playerDefault = Popcorn.soundcloud({ + target: "player_2", src: "http://soundcloud.com/forss/flickermood" }); - playerOverride = Popcorn.soundcloud( "player_2", { + playerOverride = Popcorn.soundcloud({ + target: "player_2", height: "100px", width: '90%', src: "http://soundcloud.com/forss/journeyman" @@ -142,7 +145,10 @@ test( "Default Attribute Functionality", function () { test( "Player Volume Control", function () { var expects = 3, count = 0, - player = Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ), + player = Popcorn.soundcloud({ + target: "player_1", + src: "http://soundcloud.com/forss/flickermood" + }), targetVolume, startVolume; @@ -186,14 +192,21 @@ test( "Testing Comments", function() { cmtDate = new Date(), comment, players = { - player1: Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ), - player2: Popcorn.soundcloud( "player_2", { + player1: Popcorn.soundcloud({ + target: "player_1", + src: "http://soundcloud.com/forss/flickermood" + }), + player2: Popcorn.soundcloud({ + target: "player_2", src: "http://soundcloud.com/forss/flickermood", commentformat: function( comment ) { return comment.text } }), - player3: Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ) + player3: Popcorn.soundcloud({ + target: "player_1", + src: "http://soundcloud.com/forss/flickermood" + }) } // Expecteed comment output commentOutput = { @@ -254,7 +267,10 @@ test( "Testing Comments", function() { test( "Popcorn Integration", function () { var expects = 4, count = 0, - player = Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ); + player = Popcorn.soundcloud({ + target: "player_1", + src: "http://soundcloud.com/forss/flickermood" + }); function plus() { if ( ++count === expects ) { @@ -296,7 +312,10 @@ test( "Popcorn Integration", function () { test( "Events and Player Control", function () { var expects = 14, count = 0, - player = Popcorn.soundcloud( "player_1", { src: "http://soundcloud.com/forss/flickermood" } ), + player = Popcorn.soundcloud({ + target: "player_1", + src: "http://soundcloud.com/forss/flickermood" + }), targetVolume; function plus() { @@ -306,7 +325,7 @@ test( "Events and Player Control", function () { } expect(expects); - stop( 100000 ); + stop( 150000 ); player.addEventListener( "load", function() { ok( true, "Load was fired" );