From bc374ef51358cbce286e595be086d2d1f0e30cb2 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Fri, 9 Mar 2018 22:11:27 +0530 Subject: [PATCH] video auutoplay, reset video --- example/example.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/example/example.js b/example/example.js index 6554041..28c2d2c 100644 --- a/example/example.js +++ b/example/example.js @@ -9,7 +9,8 @@ init() function init() { document.querySelectorAll('.slide').forEach(function(slide) { slides.push(slide) - var data = slideData[slides.length - 1] = load_slide(slide) + var data = slideData[slides.length - 1] = load_slide(slide); + data.idx = slides.length - 1; if (data.video && data.video.length) { data.embed = init_embed(data) } @@ -26,7 +27,7 @@ function go(idx) { clearTimeout(timeout) timeout = null } - //timeout = setTimeout(next, Math.round(slides[current].dataset.duration) * 1000) + timeout = setTimeout(next, Math.round(slides[current].dataset.duration) * 1000) // stop(old) start(current) @@ -62,7 +63,7 @@ function stop(idx) { if (data.zoom_to) { reset_zoom(data) } else if (data.video && data.video.length) { - pause_video(data) + reset_video(data) } } @@ -93,12 +94,19 @@ function load_slide(slide) { function init_embed(data) { var embed = window.currentEmbed = new PandoraEmbed({ - id: 'fixme', + id: 'slide-' + data.idx, url: data.video[0], container: data.container }); embed.on('init', function(data) { + }); + embed.on('playing', function(positionData) { + if (!slideData[data.idx].start) { + slideData[data.idx].start = positionData.position; + } + }); + return embed; } @@ -135,9 +143,10 @@ function start_video(data) { }) } -function pause_video(data) { +function reset_video(data) { data.embed.postMessage('options', { - 'paused': true + 'paused': true, + 'position': data.start || 0 }) }