From 78c13a285bf0711526676472e28b92cb00fe4219 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Sat, 17 Mar 2018 15:47:13 +0530 Subject: [PATCH] wait for slide to load before starting, fixes #3 --- example/example.js | 31 ++++++++++++++++++++++++++----- example/index.html | 5 +++++ index.html | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/example/example.js b/example/example.js index e8955b4..1b8aa15 100644 --- a/example/example.js +++ b/example/example.js @@ -1,6 +1,6 @@ class Slide { constructor(slide, idx) { - this.isInit = false + this.isAudioLoaded = this.isVideoLoaded = false this.el = slide this.idx = idx this.duration = slide.dataset.duration @@ -32,8 +32,8 @@ class Slide { container: this.videoContainer }) - videoEmbed.on('init', (data) => { - this.isVideoInit = true + videoEmbed.on('loaded', () => { + this.isVideoLoaded = true }) videoEmbed.on('playing', (positionData) => { @@ -50,8 +50,8 @@ class Slide { container: this.audioContainer }) - audioEmbed.on('init', (data) => { - this.isAudioInit = true + audioEmbed.on('loaded', () => { + this.isAudioLoaded = true }) audioEmbed.on('playing', (positionData) => { @@ -64,6 +64,19 @@ class Slide { return this; } + isReady() { + console.log('isReady called'); + if (this.video && this.audio) { + return this.isVideoLoaded && this.isAudioLoaded + } else if (this.video) { + return this.isVideoLoaded + } else if (this.audio) { + return this.isAudioLoaded + } else { + return true + } + } + sendToBack() { this.el.style.zIndex = 0 return this @@ -75,6 +88,7 @@ class Slide { } start() { + console.log('called start', this.isReady()) if (this.zooms) { this.startZoom() } else if (this.video && this.video.length) { @@ -174,7 +188,14 @@ function init() { } function go(idx) { + if (!slides[idx].isReady()) { + console.log('slide not ready'); + return setTimeout(() => { + go(idx) + }, 250) + } var old = current + slides[current].sendToBack() slides[idx].bringToFront() current = idx diff --git a/example/index.html b/example/index.html index 7af8fed..7cce190 100644 --- a/example/index.html +++ b/example/index.html @@ -2,6 +2,11 @@
+
+
+
+
FROM JANTA COLONY TO JANTA COLONY
diff --git a/index.html b/index.html index c91d586..62198a2 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ Subscribe to events from pad.ma iframe embed - +