if ( !document.addEventListener ) {
global.Popcorn = {};
- var methods = ( "removeInstance destroy addInstance getInstanceById removeInstanceById " +
- "forEach extend effects error guid sizeOf isArray nop position disable enable " +
+ var methods = ( "removeInstance addInstance getInstanceById removeInstanceById " +
+ "forEach extend effects error guid sizeOf isArray nop position disable enable destroy " +
"addTrackEvent removeTrackEvent getTrackEvents getTrackEvent getLastTrackEventId " +
"timeUpdate plugin removePlugin compose effect parser xhr getJSONP getScript" ).split(/\s+/);
readyStack = [],
readyBound = false,
readyFired = false,
+ isDestroyed = false,
// Non-public internal data object
internal = {
return Popcorn.instances;
};
- Popcorn.destroy = function( instance ) {
- var events = instance.data.events,
- singleEvent;
-
- // Iterate through all events and remove them
- for( item in events ) {
- singleEvent = events[ item ];
- for( fn in singleEvent ) {
- delete singleEvent[ fn ];
- }
- events[ item ] = null;
- }
-
- if ( instance.media.readyState >= 2 ) {
- instance.media.removeEventListener( "timeupdate", instance.data.timeUpdateFunction, false );
- } else {
- throw ( "Attempting to remove event listener before event has been added!" );
- }
-
- Popcorn.removeInstance( instance );
- };
-
// Addes a Popcorn instance to the Popcorn instance array
Popcorn.addInstance = function( instance ) {
} else {
that.data.timeUpdateFunction = function( event ) {
- console.log( "in time update" );
Popcorn.timeUpdate( that, event );
}
- that.media.addEventListener( "timeupdate", that.data.timeUpdateFunction, false );
+ !isDestroyed && that.media.addEventListener( "timeupdate", that.data.timeUpdateFunction, false );
}
} else {
global.setTimeout(function() {
}
return instance;
+ },
+ destroy: function( instance ) {
+ var events = instance.data.events,
+ singleEvent, item, fn;
+
+ // Iterate through all events and remove them
+ for ( item in events ) {
+ singleEvent = events[ item ];
+ for ( fn in singleEvent ) {
+ delete singleEvent[ fn ];
+ }
+ events[ item ] = null;
+ }
+
+ instance.media.removeEventListener( "timeupdate", instance.data.timeUpdateFunction, false );
+ isDestroyed = true;
+
+ Popcorn.removeInstance( instance );
}
});
+++ /dev/null
-<html>
- <head>
- <script src="popcorn.js"></script>
- <script>
- var popcorn;
-
- function destroy() {
- popcorn.destroy();
- }
-
-
- document.addEventListener( "DOMContentLoaded", function( event ) {
- popcorn = Popcorn( "#video" );
-
- popcorn.listen( "timeupdate", function() { });
- popcorn.listen( "play", function() {});
-
- for( item in popcorn.data.events ) {
- console.log( "EVENT: ", popcorn.data.events[ item ] );
- }
-
- //popcorn.destroy();
-
- }, false );
- </script>
- </head>
- <body>
- <button onclick="destroy()">DESTROY</button>
-
- <video id='video'
- style="display:;width:300px"
- controls
- preload="auto">
-
- <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"'>
-
- <source id='webm'
- src="test/trailer.webm"
- type='video/webm; codecs="vp8, vorbis"'>
-
- <p>Your user agent does not support the HTML5 Video element.</p>
- </video>
- </body>
-</html>