bloom-player 2.20.3-alpha.1 → 2.21.1-alpha.1
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.
|
|
6
|
+
"version": "2.21.1-alpha.1",
|
|
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": "",
|
package/src/shared/narration.ts
CHANGED
|
@@ -1032,12 +1032,12 @@ function getPreloadPlayer(): HTMLAudioElement {
|
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
1034
|
function preloadAudioForElement(element: Element): void {
|
|
1035
|
-
const
|
|
1036
|
-
const id =
|
|
1035
|
+
const audioElement = getFirstAudioSentenceWithinElement(element) ?? element;
|
|
1036
|
+
const id = audioElement.id;
|
|
1037
1037
|
if (preloadedAudioId === id) return; // already preloading this one
|
|
1038
1038
|
|
|
1039
1039
|
const url =
|
|
1040
|
-
currentAudioUrl(id) +
|
|
1040
|
+
currentAudioUrl(id, audioElement) +
|
|
1041
1041
|
"?nocache=" +
|
|
1042
1042
|
new Date().getTime() +
|
|
1043
1043
|
"&optional=true";
|
|
@@ -1085,8 +1085,25 @@ function updatePlayerStatus() {
|
|
|
1085
1085
|
player.setAttribute("src", src);
|
|
1086
1086
|
}
|
|
1087
1087
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1088
|
+
// Bloom can name a recording's file in data-audio-src on the element that carries its id,
|
|
1089
|
+
// e.g. data-audio-src="<id>.opus". Absent => <id>.mp3 (all older books). Like the music and
|
|
1090
|
+
// drag-activity sound attributes, the value goes into the URL as is, so it must be URL-safe.
|
|
1091
|
+
export function getNarrationFileName(
|
|
1092
|
+
id: string,
|
|
1093
|
+
element: Element | null | undefined,
|
|
1094
|
+
): string {
|
|
1095
|
+
return element?.getAttribute("data-audio-src") || id + ".mp3";
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// Neighboring pages stay in the DOM and can reuse ids, so prefer the element we were
|
|
1099
|
+
// given, then one on the current page, before searching the whole document.
|
|
1100
|
+
export function currentAudioUrl(id: string, element?: Element | null): string {
|
|
1101
|
+
const audioElement =
|
|
1102
|
+
element ??
|
|
1103
|
+
currentPlayPage?.querySelector(`[id="${id}"]`) ??
|
|
1104
|
+
document.getElementById(id);
|
|
1105
|
+
const result =
|
|
1106
|
+
urlPrefix() + "/audio/" + getNarrationFileName(id, audioElement);
|
|
1090
1107
|
return result;
|
|
1091
1108
|
}
|
|
1092
1109
|
|