From f23160d67b1e8db622c48221a2c1b07872f2efd7 Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Thu, 24 Jan 2013 09:25:17 +0100 Subject: [PATCH] Preload video, to avoid wait when pressing finish-button --- js/questionset.js | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 88e3847..ad1686b 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -233,32 +233,37 @@ H5P.QuestionSet = function (options, contentId) { finishButtonText: params.endGame.resultPage.finishButtonText }; endTemplate.update(target.attr('id'), eparams); + + var $video; + if (params.endGame.animations.showAnimations) { + var sources = ""; + var videoData = success ? params.endGame.animations.successVideo : params.endGame.animations.failVideo; + + if (videoData) { + for (var key in videoData) { + sources += ''; + } + // TODO: Width/height from somewhere. + $video = $(''); + $video[0].autoplay = false; + $video[0].load(); + } + } + $('.qs-finishbutton').click(function (ev) { // Display animation if present. - if (params.endGame.animations.showAnimations) { - // Init anims. - console.log("Now we should have started some anims..."); - var sources = ""; - var videoData = success ? params.endGame.animations.successVideo : params.endGame.animations.failVideo; - - if (videoData) { - for (var key in videoData) { - sources += ''; - } - // TODO: Width/height from somewhere. - var $video = $(''); - - target.html($video); - $video.on('play', function(ev) { - console.log('Video started playing!!!'); - }).on('ended', function(ev) { - console.log('Video is finished, quitting now!'); - // On animation finished: - $(returnObject).trigger('h5pQuestionSetFinished', eventData); - }); - // Play vidoi! - $video[0].play(); - } + if ($video) { + // Start video. + target.html($video); + $video.on('play', function(ev) { + console.log('Video started playing!!!'); + }).on('ended', function(ev) { + console.log('Video is finished, quitting now!'); + // On animation finished: + $(returnObject).trigger('h5pQuestionSetFinished', eventData); + }); + // Press play on tape! + $video[0].play(); } else { // Trigger finished event. $(returnObject).trigger('h5pQuestionSetFinished', eventData);