diff --git a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
index 786170a0d..070f448b3 100644
--- a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
+++ b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -102,7 +102,7 @@
self._util.type = "YouTube";
function addMediaReadyCallback( callback ) {
- mediaReadyCallbacks.unshift( callback );
+ mediaReadyCallbacks.push( callback );
}
function onPlayerReady( event ) {
@@ -279,14 +279,18 @@
if( !( playerReady && player ) ) {
return;
}
+ onPause();
durationReady = false;
+ mediaReady = false;
firstPlay = false;
+ loopedPlay = false;
+ impl.currentTime = 0;
+ mediaReadyCallbacks = [];
clearInterval( currentTimeInterval );
clearInterval( bufferedInterval );
player.stopVideo();
player.clearVideo();
player.destroy();
- mediaReadyCallbacks = [];
elem = document.createElement( "div" );
}
diff --git a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
index 79469f514..cfaafc445 100644
--- a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
+++ b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
@@ -99,7 +99,7 @@ var testData = {
}
});
- asyncTest( "YouTube 06 - source changes", 2, function() {
+ asyncTest( "YouTube 06 - source changes", 3, function() {
var video = testData.createMedia( "#video" );
@@ -107,8 +107,14 @@ var testData = {
ok( true, "first source ready event is fired" );
video.removeEventListener( "loadedmetadata", loadedmetadata, false );
video.addEventListener( "loadedmetadata", function() {
+ video.pause();
ok( true, "second source ready event is fired" );
- start();
+ video.addEventListener( "play", function() {
+ equal( video.currentTime, 2, "times change properly after source changes" );
+ start();
+ }, false );
+ video.currentTime = 2;
+ video.play();
}, false );
video.src = "http://www.youtube.com/watch?v=HMnyrTe-j6U&autoplay=1&loop=1";
}, false );