bloom-player 2.20.1 → 2.20.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.20.1",
6
+ "version": "2.20.2",
7
7
  "packageManager": "pnpm@11.1.2",
8
8
  "private": false,
9
9
  "// sideeffects might need to be ['*.css'] to avoid 'shaking' our CSS, if we ever get tree shaking working": "",
@@ -14,6 +14,7 @@
14
14
 
15
15
  import { ActivityManager } from "../activities/activityManager";
16
16
  import {
17
+ cancelVideoFirstFramePriming,
17
18
  kAudioSentence,
18
19
  playAllAudio,
19
20
  playAllVideo,
@@ -43,7 +44,7 @@ let positionsToRestore: { x: string; y: string; elt: HTMLElement }[] = [];
43
44
  // Save the current positions of all draggables (when entering Play tab, so we can restore them when leaving).
44
45
  const savePositions = (page: HTMLElement) => {
45
46
  positionsToRestore = [];
46
- page.querySelectorAll("[data-draggable-id]").forEach((elt: HTMLElement) => {
47
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]").forEach((elt) => {
47
48
  positionsToRestore.push({
48
49
  x: elt.style.left,
49
50
  y: elt.style.top,
@@ -66,7 +67,9 @@ export function adjustDraggablesForLanguage(page: HTMLElement) {
66
67
  if (page.getAttribute("data-activity") !== "drag-letter-to-target") {
67
68
  return;
68
69
  }
69
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
70
+ const draggables = Array.from(
71
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
72
+ );
70
73
  draggables.shift(); // The first one is always visible.
71
74
  draggables.forEach((draggable: HTMLElement) => {
72
75
  const shouldBeVisible = !!(
@@ -110,7 +113,9 @@ export function prepareActivity(
110
113
 
111
114
  // Set up event listeners for any change page buttons.
112
115
  const changePageButtons = Array.from(
113
- page.getElementsByClassName("bloom-change-page-button"),
116
+ page.getElementsByClassName(
117
+ "bloom-change-page-button",
118
+ ) as HTMLCollectionOf<HTMLElement>,
114
119
  );
115
120
  changePageButtons.forEach((b) =>
116
121
  b.addEventListener("click", changePageButtonClicked),
@@ -138,7 +143,9 @@ export function prepareActivity(
138
143
  // Add event listeners to draggables to start dragging.
139
144
  targetPositions = [];
140
145
  originalPositions = new Map<HTMLElement, { x: number; y: number }>();
141
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
146
+ const draggables = Array.from(
147
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
148
+ );
142
149
  const targets: HTMLElement[] = [];
143
150
  draggables.forEach((elt: HTMLElement) => {
144
151
  const targetId = elt.getAttribute("data-draggable-id");
@@ -180,9 +187,7 @@ export function prepareActivity(
180
187
  // Ensure the first frame is visible. The transparent poster (set globally by
181
188
  // bloom-player at book load) hides the video until playback begins. Non-draggable
182
189
  // videos get a play+pause first-frame trick in video.ts HandlePageVisible, but
183
- // draggable videos are skipped there. If the video source hasn't loaded yet
184
- // (e.g. cold cache after a build), play() fails silently, leaving the video blank.
185
- // We use a loadeddata listener so the trick runs whenever the data is available.
190
+ // draggable videos are skipped there, so they depend entirely on this call.
186
191
  showVideoFirstFrameWhenReady(video);
187
192
  }
188
193
  });
@@ -190,7 +195,9 @@ export function prepareActivity(
190
195
  // Add event listeners to (other) text items that should play audio when clicked.
191
196
  const dontPlayWhenClicked = draggables.concat(targets);
192
197
  const otherTextItems = Array.from(
193
- page.getElementsByClassName("bloom-visibility-code-on"),
198
+ page.getElementsByClassName(
199
+ "bloom-visibility-code-on",
200
+ ) as HTMLCollectionOf<HTMLElement>,
194
201
  ).filter((e) => {
195
202
  var top = e.closest(kLegacyCanvasElementSelector) as HTMLElement;
196
203
  if (!top) {
@@ -209,13 +216,19 @@ export function prepareActivity(
209
216
 
210
217
  // Add event listeners to check, try again, and show correct buttons.
211
218
  const checkButtons = Array.from(
212
- page.getElementsByClassName("check-button"),
219
+ page.getElementsByClassName(
220
+ "check-button",
221
+ ) as HTMLCollectionOf<HTMLElement>,
213
222
  );
214
223
  const tryAgainButtons = Array.from(
215
- page.getElementsByClassName("try-again-button"),
224
+ page.getElementsByClassName(
225
+ "try-again-button",
226
+ ) as HTMLCollectionOf<HTMLElement>,
216
227
  );
217
228
  const showCorrectButtons = Array.from(
218
- page.getElementsByClassName("show-correct-button"),
229
+ page.getElementsByClassName(
230
+ "show-correct-button",
231
+ ) as HTMLCollectionOf<HTMLElement>,
219
232
  );
220
233
 
221
234
  checkButtons.forEach((elt: HTMLElement) => {
@@ -228,7 +241,9 @@ export function prepareActivity(
228
241
  elt.addEventListener("click", showCorrect);
229
242
  });
230
243
 
231
- const soundItems = Array.from(page.querySelectorAll("[data-sound]"));
244
+ const soundItems = Array.from(
245
+ page.querySelectorAll<HTMLElement>("[data-sound]"),
246
+ );
232
247
  soundItems.forEach((elt: HTMLElement) => {
233
248
  elt.addEventListener("click", playSoundOf);
234
249
  });
@@ -254,7 +269,11 @@ export function prepareActivity(
254
269
  // Break any order-sentence element into words and
255
270
  // randomize word order in sentence for reader to sort
256
271
  const prepareOrderSentenceActivity = (page: HTMLElement) => {
257
- Array.from(page.getElementsByClassName("drag-item-order-sentence")).forEach(
272
+ Array.from(
273
+ page.getElementsByClassName(
274
+ "drag-item-order-sentence",
275
+ ) as HTMLCollectionOf<HTMLElement>,
276
+ ).forEach(
258
277
  (elt: HTMLElement) => {
259
278
  const contentElt = elt.getElementsByClassName(
260
279
  "bloom-content1 bloom-visibility-code-on",
@@ -277,6 +296,9 @@ const prepareOrderSentenceActivity = (page: HTMLElement) => {
277
296
 
278
297
  const playVideo = (e: MouseEvent) => {
279
298
  const video = e.currentTarget as HTMLVideoElement;
299
+ // The user asked for real playback; a pending first-frame priming attempt
300
+ // must not mute or pause it.
301
+ cancelVideoFirstFramePriming(video);
280
302
  video.play();
281
303
  };
282
304
 
@@ -291,19 +313,23 @@ export function undoPrepareActivity(page: HTMLElement) {
291
313
  positionsToRestore = [];
292
314
 
293
315
  const changePageButtons = Array.from(
294
- page.getElementsByClassName("bloom-change-page-button"),
316
+ page.getElementsByClassName(
317
+ "bloom-change-page-button",
318
+ ) as HTMLCollectionOf<HTMLElement>,
295
319
  );
296
320
  changePageButtons.forEach((b) =>
297
321
  b.removeEventListener("click", changePageButtonClicked),
298
322
  );
299
323
 
300
- Array.from(page.getElementsByClassName("bloom-visibility-code-on")).forEach(
301
- (e) => {
302
- e.removeEventListener("pointerdown", playAudioOfTarget);
303
- },
304
- );
324
+ Array.from(
325
+ page.getElementsByClassName(
326
+ "bloom-visibility-code-on",
327
+ ) as HTMLCollectionOf<HTMLElement>,
328
+ ).forEach((e) => {
329
+ e.removeEventListener("pointerdown", playAudioOfTarget);
330
+ });
305
331
 
306
- page.querySelectorAll("[data-draggable-id]").forEach((elt: HTMLElement) => {
332
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]").forEach((elt) => {
307
333
  elt.removeEventListener("pointerdown", startDrag, { capture: true });
308
334
  });
309
335
 
@@ -317,13 +343,19 @@ export function undoPrepareActivity(page: HTMLElement) {
317
343
  video.classList.remove("bloom-ui-no-controls");
318
344
  });
319
345
  const checkButtons = Array.from(
320
- page.getElementsByClassName("check-button"),
346
+ page.getElementsByClassName(
347
+ "check-button",
348
+ ) as HTMLCollectionOf<HTMLElement>,
321
349
  );
322
350
  const tryAgainButtons = Array.from(
323
- page.getElementsByClassName("try-again-button"),
351
+ page.getElementsByClassName(
352
+ "try-again-button",
353
+ ) as HTMLCollectionOf<HTMLElement>,
324
354
  );
325
355
  const showCorrectButtons = Array.from(
326
- page.getElementsByClassName("show-correct-button"),
356
+ page.getElementsByClassName(
357
+ "show-correct-button",
358
+ ) as HTMLCollectionOf<HTMLElement>,
327
359
  );
328
360
 
329
361
  checkButtons.forEach((elt: HTMLElement) => {
@@ -339,13 +371,17 @@ export function undoPrepareActivity(page: HTMLElement) {
339
371
  // In Bloom Player, this will have been done by other play code, since data-sound is not
340
372
  // specific to games. But we're adding a listener for the same function, so it doesn't matter.
341
373
  // In Bloom desktop, we need this to make clicking data-sound elements work in Play mode.
342
- const soundItems = Array.from(page.querySelectorAll("[data-sound]"));
374
+ const soundItems = Array.from(
375
+ page.querySelectorAll<HTMLElement>("[data-sound]"),
376
+ );
343
377
  soundItems.forEach((elt: HTMLElement) => {
344
378
  elt.removeEventListener("click", playSoundOf);
345
379
  });
346
380
 
347
381
  Array.from(
348
- page.getElementsByClassName("drag-item-random-sentence"),
382
+ page.getElementsByClassName(
383
+ "drag-item-random-sentence",
384
+ ) as HTMLCollectionOf<HTMLElement>,
349
385
  ).forEach((elt: HTMLElement) => {
350
386
  elt.parentElement?.removeChild(elt);
351
387
  });
@@ -602,7 +638,7 @@ const showCorrect = (e: MouseEvent) => {
602
638
  }
603
639
  restorePositions(); // any distractors return to start positions.
604
640
  currentPage
605
- .querySelectorAll("[data-draggable-id]")
641
+ .querySelectorAll<HTMLElement>("[data-draggable-id]")
606
642
  .forEach((elt: HTMLElement) => {
607
643
  const targetId = elt.getAttribute("data-draggable-id");
608
644
  const target = currentPage?.querySelector(
@@ -631,7 +667,9 @@ const showCorrect = (e: MouseEvent) => {
631
667
  elt.style.top = y + "px";
632
668
  });
633
669
  Array.from(
634
- currentPage.getElementsByClassName("drag-item-random-sentence"),
670
+ currentPage.getElementsByClassName(
671
+ "drag-item-random-sentence",
672
+ ) as HTMLCollectionOf<HTMLElement>,
635
673
  ).forEach((container: HTMLElement) => {
636
674
  const correctAnswer =
637
675
  container.getAttribute("data-answer")?.split(" ") ?? [];
@@ -651,7 +689,7 @@ const showCorrect = (e: MouseEvent) => {
651
689
  // Play any videos that are part of a correct answer, in document order.
652
690
  const videoElements: HTMLVideoElement[] = [];
653
691
  currentPage!
654
- .querySelectorAll("[data-draggable-id]")
692
+ .querySelectorAll<HTMLElement>("[data-draggable-id]")
655
693
  .forEach((elt: HTMLElement) => {
656
694
  const targetId = elt.getAttribute("data-draggable-id");
657
695
  const target = currentPage?.querySelector(
@@ -751,7 +789,9 @@ const stopDrag = (e: PointerEvent) => {
751
789
  // back to its original position.
752
790
  // Enhance: animate?
753
791
  const page = dragTarget.closest(".bloom-page") as HTMLElement;
754
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
792
+ const draggables = Array.from(
793
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
794
+ );
755
795
  draggables.forEach((elt: HTMLElement) => {
756
796
  if (elt === dragTarget) {
757
797
  return;
@@ -944,6 +984,19 @@ function showCorrectOrWrongItems(page: HTMLElement, correct: boolean) {
944
984
  classSetter(page, "drag-activity-wrong", !correct);
945
985
 
946
986
  const playOtherStuff = () => {
987
+ // This runs when the correct/wrong sound finishes, which may be after
988
+ // the user has already clicked "Show Correct" or "Try Again". Those
989
+ // take the page out of the state this feedback belongs to, and
990
+ // "Show Correct" starts playing the solution videos, which the
991
+ // playAllVideo call below would silently cancel (BL-16146). If the
992
+ // page is no longer showing the state we were queued for, do nothing.
993
+ if (
994
+ !page.parentElement?.classList.contains(
995
+ correct ? "drag-activity-correct" : "drag-activity-wrong",
996
+ )
997
+ ) {
998
+ return;
999
+ }
947
1000
  const elementsMadeVisible = Array.from(
948
1001
  page.getElementsByClassName(
949
1002
  correct ? "drag-item-correct" : "drag-item-wrong",
@@ -1029,7 +1082,9 @@ function playSound(
1029
1082
 
1030
1083
  function checkDraggables(page: HTMLElement) {
1031
1084
  let allCorrect = true;
1032
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
1085
+ const draggables = Array.from(
1086
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
1087
+ );
1033
1088
  draggables.forEach((draggableToCheck: HTMLElement) => {
1034
1089
  const targetId = draggableToCheck.getAttribute("data-draggable-id");
1035
1090
  const target = page.querySelector(
@@ -386,8 +386,8 @@ function removeHighlightClasses(element: HTMLElement) {
386
386
  element.classList.remove(kDisableHighlightClass);
387
387
  element.classList.remove(kEnableHighlightClass);
388
388
 
389
- Array.from(element.children).forEach((child: HTMLElement) => {
390
- removeHighlightClasses(child);
389
+ Array.from(element.children).forEach((child) => {
390
+ removeHighlightClasses(child as HTMLElement);
391
391
  });
392
392
  }
393
393
 
@@ -1266,7 +1266,7 @@ function getPageAudioElements(
1266
1266
  page?: HTMLElement,
1267
1267
  canvasToExclude?: HTMLElement,
1268
1268
  ): HTMLElement[] {
1269
- return [].concat.apply(
1269
+ return ([] as HTMLElement[]).concat.apply(
1270
1270
  [],
1271
1271
  getPagePlayableDivs(page, canvasToExclude).map((x) =>
1272
1272
  findAll(".audio-sentence", x, true),
@@ -1401,94 +1401,134 @@ export function isTransientVideoPlayFailure(reason: any): boolean {
1401
1401
  return message.includes("interrupted by a call to pause()");
1402
1402
  }
1403
1403
 
1404
- // Attempt to show a video's first frame by briefly starting playback and then pausing.
1405
- // The callback allows callers to decide at the moment playback starts whether pausing
1406
- // is still desired (for example, page-level logic may stop pausing after initial load).
1404
+ // Cancel functions for in-progress first-frame priming attempts (see
1405
+ // showVideoFirstFrameWhenReady below), keyed by the video being primed.
1406
+ const firstFramePrimingCancels = new WeakMap<HTMLVideoElement, () => void>();
1407
+
1408
+ // Anything about to start real playback of a video should call this first:
1409
+ // if a first-frame priming attempt is in progress on the video, it is
1410
+ // cancelled (restoring the video's muted state and removing the transparent
1411
+ // poster) so the primer can't mute or pause the real playback.
1412
+ export function cancelVideoFirstFramePriming(video: HTMLVideoElement) {
1413
+ firstFramePrimingCancels.get(video)?.();
1414
+ }
1415
+
1416
+ // Attempt to show a video's first frame by briefly starting muted playback and
1417
+ // then pausing. We mute while priming because gestureless unmuted play() is
1418
+ // rejected by autoplay policies (iOS especially, where a past tap elsewhere on
1419
+ // the page grants nothing). Calling play() is also what forces browsers that
1420
+ // don't preload video data (again, iOS Safari) to fetch and decode the first
1421
+ // frame, so we must not wait for loadeddata first: on iOS it typically never
1422
+ // fires until something plays. (BL-16146)
1423
+ // The callback allows callers to decide at the moment playback starts whether
1424
+ // pausing is still desired (for example, page-level logic may stop pausing
1425
+ // after initial load).
1407
1426
  export function showVideoFirstFrameWhenReady(
1408
1427
  video: HTMLVideoElement,
1409
1428
  shouldPauseAfterPlaying: () => boolean = () => true,
1410
1429
  onAutoplayBlocked: () => void = () => showVideoAutoplayBlockedHint(video),
1411
1430
  ) {
1412
- let canceled = false;
1413
- const attempt = () => {
1414
- if (canceled) {
1431
+ // If something else has already started playback, don't interfere.
1432
+ if (!video.paused) {
1433
+ return;
1434
+ }
1435
+ // If an earlier priming attempt on this video is still armed (e.g. the
1436
+ // page was left and re-entered within the give-up window), cancel it so
1437
+ // there is only ever one live attempt per video — otherwise the old
1438
+ // attempt's listeners/timer linger, and this attempt would wrongly record
1439
+ // the old attempt's muting as the video's real muted state.
1440
+ cancelVideoFirstFramePriming(video);
1441
+ const wasMuted = video.muted;
1442
+ let giveUpTimeout: number | undefined;
1443
+ let done = false;
1444
+ // Idempotent cleanup: whatever way the priming attempt ends, restore the
1445
+ // video's real muted state and stop listening.
1446
+ const finish = () => {
1447
+ if (done) {
1415
1448
  return;
1416
1449
  }
1417
- // If something else has already started playback, don't attach our
1418
- // pause-on-playing behavior.
1419
- if (!video.paused) {
1450
+ done = true;
1451
+ // Deregister only our own cancel function, in case a newer priming
1452
+ // attempt has already replaced it.
1453
+ if (firstFramePrimingCancels.get(video) === cancel) {
1454
+ firstFramePrimingCancels.delete(video);
1455
+ }
1456
+ window.clearTimeout(giveUpTimeout);
1457
+ video.removeEventListener("playing", playingListener);
1458
+ video.muted = wasMuted;
1459
+ };
1460
+ // Let real-playback initiators cancel this priming attempt so it can't
1461
+ // mute or pause the playback they are about to start.
1462
+ const cancel = () => {
1463
+ finish();
1464
+ // Real playback is starting; make sure our transparent poster can't
1465
+ // hide it.
1466
+ video.removeAttribute("poster");
1467
+ };
1468
+ firstFramePrimingCancels.set(video, cancel);
1469
+ const playingListener = () => {
1470
+ hideVideoAutoplayBlockedHint(video);
1471
+ if (!shouldPauseAfterPlaying()) {
1472
+ // Real playback has taken over; restore audio and get out of the way.
1473
+ finish();
1474
+ video.removeAttribute("poster");
1420
1475
  return;
1421
1476
  }
1422
- const playingListener = () => {
1423
- window.clearTimeout(removePlayingListenerTimeout);
1424
- hideVideoAutoplayBlockedHint(video);
1425
- if (!shouldPauseAfterPlaying()) {
1426
- return;
1477
+ const pauseIfStillWanted = () => {
1478
+ if (done) {
1479
+ return; // we already gave up or something else took over
1427
1480
  }
1428
- const pauseIfStillWanted = () => {
1429
- if (shouldPauseAfterPlaying()) {
1430
- video.pause();
1431
- }
1432
- };
1433
- // Prefer pausing after a composited video frame, not just after a timer.
1434
- // Some videos/devices can report "playing" before pixels are actually painted.
1435
- const requestVideoFrameCallback = (video as any)
1436
- .requestVideoFrameCallback as
1437
- | ((callback: (...args: any[]) => void) => number)
1438
- | undefined;
1439
- if (requestVideoFrameCallback) {
1440
- requestVideoFrameCallback.call(video, () => {
1441
- pauseIfStillWanted();
1442
- });
1443
- } else {
1444
- // Fallback for older browsers. This sometimes helps, but is not as reliable as the
1445
- // above on browsers that implement it.
1446
- setTimeout(() => {
1447
- pauseIfStillWanted();
1448
- }, 4);
1481
+ if (shouldPauseAfterPlaying()) {
1482
+ video.pause();
1449
1483
  }
1484
+ finish();
1485
+ // A frame has been painted; the transparent poster (set at book
1486
+ // load to hide videos until then) is no longer wanted.
1487
+ video.removeAttribute("poster");
1450
1488
  };
1451
- video.addEventListener("playing", playingListener, { once: true });
1452
- // If our play() attempt doesn't lead to playback soon, remove the
1453
- // listener so it can't affect unrelated later playback.
1454
- const removePlayingListenerTimeout = window.setTimeout(() => {
1455
- video.removeEventListener("playing", playingListener);
1456
- }, 1000);
1457
- hideVideoAutoplayBlockedHint(video);
1458
- const promise = video.play();
1459
- if (promise && promise.catch) {
1460
- promise.catch((reason) => {
1461
- window.clearTimeout(removePlayingListenerTimeout);
1462
- // If play() fails (e.g., autoplay policy), remove the listener
1463
- // so it won't interfere if playback starts later by other means.
1464
- video.removeEventListener("playing", playingListener);
1465
- // If autoplay is blocked, remove our transparent poster so a decoded
1466
- // first frame can be shown when available.
1467
- if (reason?.name === "NotAllowedError") {
1468
- video.removeAttribute("poster");
1469
- onAutoplayBlocked();
1470
- }
1489
+ // Prefer pausing after a composited video frame, not just after a timer.
1490
+ // Some videos/devices can report "playing" before pixels are actually painted.
1491
+ const requestVideoFrameCallback = (video as any)
1492
+ .requestVideoFrameCallback as
1493
+ | ((callback: (...args: any[]) => void) => number)
1494
+ | undefined;
1495
+ if (requestVideoFrameCallback) {
1496
+ requestVideoFrameCallback.call(video, () => {
1497
+ pauseIfStillWanted();
1471
1498
  });
1499
+ } else {
1500
+ // Fallback for older browsers. This sometimes helps, but is not as reliable as the
1501
+ // above on browsers that implement it.
1502
+ setTimeout(() => {
1503
+ pauseIfStillWanted();
1504
+ }, 4);
1472
1505
  }
1473
1506
  };
1474
- // HAVE_CURRENT_DATA (2) means at least the first frame is decoded.
1475
- if (video.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
1476
- attempt();
1477
- } else {
1478
- let cancelAttempt: () => void;
1479
- const onLoadedData = () => {
1480
- video.removeEventListener("play", cancelAttempt);
1481
- attempt();
1482
- };
1483
- cancelAttempt = () => {
1484
- canceled = true;
1485
- video.removeEventListener("loadeddata", onLoadedData);
1486
- video.removeEventListener("play", cancelAttempt);
1487
- };
1488
- // If something requests playback before the video has loaded enough data,
1489
- // don't run this first-frame trick when loadeddata eventually fires.
1490
- video.addEventListener("play", cancelAttempt, { once: true });
1491
- video.addEventListener("loadeddata", onLoadedData, { once: true });
1507
+ video.addEventListener("playing", playingListener, { once: true });
1508
+ // If nothing has painted after a while (very slow data, or a policy we
1509
+ // didn't anticipate), give up: cancel our pending muted playback, restore
1510
+ // audio, and remove the transparent poster so the browser can show its own
1511
+ // first frame when it has one, rather than leaving the video invisible.
1512
+ giveUpTimeout = window.setTimeout(() => {
1513
+ if (shouldPauseAfterPlaying() && !video.paused) {
1514
+ video.pause();
1515
+ }
1516
+ finish();
1517
+ video.removeAttribute("poster");
1518
+ }, 3000);
1519
+ hideVideoAutoplayBlockedHint(video);
1520
+ video.muted = true;
1521
+ const promise = video.play();
1522
+ if (promise && promise.catch) {
1523
+ promise.catch((reason) => {
1524
+ finish();
1525
+ // If autoplay is blocked even muted, remove our transparent poster
1526
+ // so a decoded first frame can be shown when available.
1527
+ if (reason?.name === "NotAllowedError") {
1528
+ video.removeAttribute("poster");
1529
+ onAutoplayBlocked();
1530
+ }
1531
+ });
1492
1532
  }
1493
1533
  }
1494
1534
 
@@ -1558,6 +1598,9 @@ function playAllVideoInternal(
1558
1598
  hideVideoError(video);
1559
1599
  hideVideoAutoplayBlockedHint(video);
1560
1600
  setCurrentPlaybackMode(PlaybackMode.VideoPlaying);
1601
+ // This is real playback; a pending first-frame priming attempt must
1602
+ // not mute or pause it.
1603
+ cancelVideoFirstFramePriming(video);
1561
1604
  // Always play each queued video from the beginning.
1562
1605
  // Without this, a previously played element may remain at end-of-stream
1563
1606
  // and fail to raise the expected ended event for sequencing.
@@ -345,8 +345,14 @@ export function setupSpecialMouseTrackingForNiceScroll(
345
345
  bloomPage: Element,
346
346
  pointerEventHandler?: (e: PointerEvent) => void,
347
347
  ) {
348
- bloomPage.removeEventListener("pointerdown", listenForPointerDown); // only want one!
349
- bloomPage.addEventListener("pointerdown", listenForPointerDown);
348
+ bloomPage.removeEventListener(
349
+ "pointerdown",
350
+ listenForPointerDown as EventListener,
351
+ ); // only want one!
352
+ bloomPage.addEventListener(
353
+ "pointerdown",
354
+ listenForPointerDown as EventListener,
355
+ );
350
356
  if (!pointerEventHandler) {
351
357
  return;
352
358
  }
@@ -355,7 +361,7 @@ export function setupSpecialMouseTrackingForNiceScroll(
355
361
  for (const eventName of ["pointermove", "pointerup"]) {
356
362
  bloomPage.ownerDocument.body.addEventListener(
357
363
  eventName,
358
- pointerEventHandler,
364
+ pointerEventHandler as EventListener,
359
365
  {
360
366
  capture: true,
361
367
  },