From 8e088386982fe8a0df091cffa872bd6b2e0fd3b7 Mon Sep 17 00:00:00 2001 From: erwin mombay Date: Fri, 9 Dec 2022 12:16:48 -0800 Subject: [PATCH] Add a 10ms delay when rewinding a media pool video (#38576) * Add a 10ms delay when rewinding * add additional context to hacky fix (cherry picked from commit 811596e2d5fa144ec54b95d10e07cc2eab066110) --- extensions/amp-story/1.0/media-pool.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/amp-story/1.0/media-pool.js b/extensions/amp-story/1.0/media-pool.js index 76bf12a02b60..3f7dc606bac6 100644 --- a/extensions/amp-story/1.0/media-pool.js +++ b/extensions/amp-story/1.0/media-pool.js @@ -807,10 +807,19 @@ export class MediaPool { return this.enqueueMediaElementTask_(poolMediaEl, new PauseTask()).then( () => { if (rewindToBeginning) { - this.enqueueMediaElementTask_( - /** @type {!PoolBoundElementDef} */ (poolMediaEl), - new SetCurrentTimeTask({currentTime: 0}) - ); + // We add a 10 second delay to rewinding as sometimes this causes an + // interlacing/glitch/frame jump when a new video is starting to play. + // A 0 delay isn't enough as we need to push the "seeking" event + // to the next tick of the event loop. + // NOTE: Please note that this is not an ideal solution and a bit hacky. + // The more ideal fix would be to fix the the navigations animation frames. + // See https://github.com/ampproject/amphtml/issues/38531 + this.timer_.delay(() => { + this.enqueueMediaElementTask_( + /** @type {!PoolBoundElementDef} */ (poolMediaEl), + new SetCurrentTimeTask({currentTime: 0}) + ); + }, 10); } } );