Preload video, to avoid wait when pressing finish-button

d3summaryChart
Frank Ronny Larsen 2013-01-24 09:25:17 +01:00
parent 393379884b
commit f23160d67b
1 changed files with 29 additions and 24 deletions

View File

@ -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 += '<source src="' + cp + videoData[key] + '" type="' + key + '">';
}
// TODO: Width/height from somewhere.
$video = $('<video width="635" height="500">' + sources + 'Stop using IE you fool</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 += '<source src="' + cp + videoData[key] + '" type="' + key + '">';
}
// TODO: Width/height from somewhere.
var $video = $('<video width="635" height="500">' + sources + 'Stop using IE you fool</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);