bloom-player 2.19.6 → 2.19.7-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A library for displaying Bloom books in iframes or WebViews",
4
4
  "author": "SIL Global",
5
5
  "license": "MIT",
6
- "version": "2.19.6",
6
+ "version": "2.19.7-alpha.2",
7
7
  "private": false,
8
8
  "// sideeffects might need to be ['*.css'] to avoid 'shaking' our CSS, if we ever get tree shaking working": "",
9
9
  "sideEffects": false,
@@ -1303,12 +1303,28 @@ export function showVideoFirstFrameWhenReady(
1303
1303
  if (!shouldPauseAfterPlaying()) {
1304
1304
  return;
1305
1305
  }
1306
- // Pause after about one frame so the first frame stays visible.
1307
- setTimeout(() => {
1306
+ const pauseIfStillWanted = () => {
1308
1307
  if (shouldPauseAfterPlaying()) {
1309
1308
  video.pause();
1310
1309
  }
1311
- }, 4);
1310
+ };
1311
+ // Prefer pausing after a composited video frame, not just after a timer.
1312
+ // Some videos/devices can report "playing" before pixels are actually painted.
1313
+ const requestVideoFrameCallback = (video as any)
1314
+ .requestVideoFrameCallback as
1315
+ | ((callback: (...args: any[]) => void) => number)
1316
+ | undefined;
1317
+ if (requestVideoFrameCallback) {
1318
+ requestVideoFrameCallback.call(video, () => {
1319
+ pauseIfStillWanted();
1320
+ });
1321
+ } else {
1322
+ // Fallback for older browsers. This sometimes helps, but is not as reliable as the
1323
+ // above on browsers that implement it.
1324
+ setTimeout(() => {
1325
+ pauseIfStillWanted();
1326
+ }, 4);
1327
+ }
1312
1328
  };
1313
1329
  video.addEventListener("playing", playingListener, { once: true });
1314
1330
  // If our play() attempt doesn't lead to playback soon, remove the