--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Popcorn Base Player Example</title>
+ <style>
+ iframe{
+ display:block;
+ border:0;
+ }
+ body > div {
+ width: 100%;
+ float: left;
+ overflow: hidden;
+ }
+ div div {
+ margin-bottom:20px;
+ }
+
+ .api_output {
+ float:right;
+ padding-left: 20px;
+ }
+ </style>
+
+
+ <script src="../../popcorn.js"></script>
+ <script type="text/javascript" src="popcorn.baseplayer.js"></script>
+
+ <script type="text/javascript">
+ //On document ready
+ document.addEventListener( "DOMContentLoaded", function() {
+ var ticks = 0,
+ player = Popcorn.baseplayer(),
+ popcorn = Popcorn( player )
+ .listen( "timeupdate", function() {
+ document.getElementById( "playerTicks" ).innerHTML = ++ticks;
+ document.getElementById( "playerMs" ).innerHTML = popcorn.currentTime();
+ });
+
+ document.getElementById( "btnPlay" ).addEventListener( "click", function() { popcorn.play(); }, false );
+ document.getElementById( "btnPause" ).addEventListener( "click", function() { popcorn.pause(); }, false );
+
+ popcorn.exec( 2, function() {
+ document.getElementById( "playerOutput" ).innerHTML = "2 seconds reached";
+ });
+
+ player.readyState = 2;
+ popcorn.play();
+ }, false);
+ </script>
+ </head>
+ <body>
+ <div>
+ Ticks: <span id="playerTicks" ></span><br />
+ Seconds: <span id="playerMs" ></span><br />
+ Event Output: <span id="playerOutput" ></span><br />
+ <button class="simple" id="btnPlay">Play</button>
+ <button class="simple" id="btnPause">Pause</button>
+ </div>
+
+ <br />
+ <br />
+ This demo showcases basic functionality of a player. It is a shell of an HTMLMediaElement with basic timing routines.<br />
+ At 2 seconds, the phrase "2 seconds reached" will appear beside 'Event Output'<br />
+ </body>
+</html>
\ No newline at end of file
--- /dev/null
+Popcorn.baseplayer = function() {
+ return new Popcorn.baseplayer.init();
+}
+
+Popcorn.baseplayer.init = function() {
+ this.readyState = 0;
+ this.currentTime = 0;
+ this.duration = 0;
+ this.paused = 1;
+ this.ended = 0;
+ this.volume = 1;
+ this.muted = 0;
+ this.playbackRate = 1;
+
+ // These are considered to be "on" by being defined. Initialize to undefined
+ this.autoplay;
+ this.loop;
+
+ // List of events
+ this.events = {};
+}
+
+Popcorn.baseplayer.init.prototype = {
+ load: function() {},
+
+ play: function() {
+ this.paused = 0;
+ this.timeupdate();
+ },
+
+ pause: function() {
+ this.paused = 1;
+ },
+
+ timeupdate: function() {
+ // The player was paused since the last time update
+ if ( this.paused ) {
+ return;
+ }
+
+ // So we can refer to the instance when setTimeout is run
+ var self = this;
+ this.currentTime += 0.015;
+
+ this.dispatchEvent( "timeupdate" );
+ setTimeout( function() {
+ self.timeupdate.call( self );
+ }, 15 );
+ },
+
+ // Add an event listener to the object
+ addEventListener: function( evtName, fn ) {
+ if ( !this.events[evtName] ) {
+ this.events[evtName] = [];
+ }
+
+ this.events[evtName].push( fn );
+ return fn;
+ },
+
+ // Can take event object or simple string
+ dispatchEvent: function( oEvent ) {
+ var evt,
+ self = this,
+ eventInterface,
+ eventName = oEvent.type;
+
+ // A string was passed, create event object
+ if ( !eventName ) {
+ eventName = oEvent;
+ eventInterface = Popcorn.events.getInterface( eventName );
+
+ if ( eventInterface ) {
+ evt = document.createEvent( eventInterface );
+ evt.initEvent( eventName, true, true, window, 1 );
+ }
+ }
+
+ Popcorn.forEach( this.events[eventName], function( val ) {
+ val.call( self, evt, self );
+ });
+ }
+};
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn Base Player Plugin</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="popcorn.baseplayer.unit.js"></script>
+ <script src="popcorn.baseplayer.js"></script>
+
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn Base Player 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>
+
+ <div id="player_1" width="500" height="281"></div>
+</body>
+</html>
--- /dev/null
+module("Popcorn Base Player");
+test("API", function () {
+
+ var expects = 17,
+ count = 0,
+ player = Popcorn.baseplayer(),
+ members = {
+ 'readyState' : 'number',
+ 'currentTime' : 'number',
+ 'duration' : 'number',
+ 'paused' : 'number',
+ 'ended' : 'number',
+ 'volume' : 'number',
+ 'muted' : 'number',
+ 'playbackRate' : 'number',
+ 'autoplay' : 'undefined',
+ 'loop' : 'undefined',
+ 'events' : 'object',
+ 'load' : 'function',
+ 'play' : 'function',
+ 'pause' : 'function',
+ 'timeupdate' : 'function',
+ 'addEventListener' : 'function',
+ 'dispatchEvent' : 'function'
+ };
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ expect(expects);
+ stop( 10000 );
+
+ Popcorn.forEach( members, function ( type, prop ) {
+ ok( typeof player[prop] === type, "player." + prop + " is type: " + type );
+ plus();
+ });
+});
+
+test("Default Functionality", function () {
+ var expects = 5,
+ count = 0,
+ player = Popcorn.baseplayer(),
+ popcorn = Popcorn( player );
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ expect(expects);
+ stop( 1000 );
+
+ player.addEventListener( 'timeupdate', function( evt, caller ) {
+ ok( true, "Time update called" );
+ plus();
+
+ equals( player, this, "'this' is kept as player" );
+ plus();
+
+ equals( player, caller, "caller is kept as player" );
+ plus();
+
+ ok( evt instanceof window.Event, "Event object passed in" );
+ plus();
+
+ ok( evt.type === 'timeupdate', "Event object is type 'timeupdate'" );
+ plus();
+
+ player.pause();
+ });
+
+ player.play();
+});
+
+test("Extension and Method Overriding", function () {
+ var expects = 3,
+ count = 0,
+ player = Popcorn.baseplayer(),
+ playerForPopcorn = Popcorn.baseplayer(),
+ popcorn;
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ expect(expects);
+ stop( 4000 );
+
+ Popcorn.extend( player, {
+ load: function() {
+ ok( true, "Load overridden" );
+ plus();
+ },
+ timeupdate: function() {
+ ok( true, "Timeupdate overridden" );
+ plus();
+ }
+ });
+
+ popcorn = Popcorn( playerForPopcorn )
+ .exec( 2, function() {
+ ok( true, "Exec triggereed from popcorn after 2 seconds" );
+ plus();
+ });
+
+ player.load();
+ player.play();
+
+ playerForPopcorn.readyState = 2;
+ popcorn.play();
+});