bloom-player 2.19.4 → 2.19.5
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
|
+
"version": "2.19.5",
|
|
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,
|
|
@@ -850,16 +850,29 @@ function showCorrectOrWrongItems(page: HTMLElement, correct: boolean) {
|
|
|
850
850
|
soundFile = undefined;
|
|
851
851
|
}
|
|
852
852
|
if (soundFile) {
|
|
853
|
-
playSound(page, soundFile, addPrefix);
|
|
853
|
+
playSound(page, soundFile, addPrefix, playOtherStuff);
|
|
854
854
|
} else {
|
|
855
855
|
playOtherStuff();
|
|
856
856
|
}
|
|
857
857
|
}
|
|
858
858
|
|
|
859
|
-
function playSound(
|
|
859
|
+
function playSound(
|
|
860
|
+
someElt: HTMLElement,
|
|
861
|
+
soundFile: string,
|
|
862
|
+
addPrefix = true,
|
|
863
|
+
then?: () => void,
|
|
864
|
+
) {
|
|
860
865
|
const audio = new Audio(
|
|
861
866
|
(addPrefix ? urlPrefix() + "/audio/" : "") + soundFile,
|
|
862
867
|
);
|
|
868
|
+
let finished = false;
|
|
869
|
+
const finish = () => {
|
|
870
|
+
if (finished) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
finished = true;
|
|
874
|
+
then?.();
|
|
875
|
+
};
|
|
863
876
|
if (IsRunningOnBloomDesktop(someElt)) {
|
|
864
877
|
audio.classList.add("bloom-ui"); // in case remove code fails, should make sure it doesn't get saved.
|
|
865
878
|
}
|
|
@@ -868,7 +881,10 @@ function playSound(someElt: HTMLElement, soundFile: string, addPrefix = true) {
|
|
|
868
881
|
// But in Bloom proper, it does not. I think it is because this code is part of the toolbox,
|
|
869
882
|
// so the audio element doesn't have the right context to interpret the relative URL.
|
|
870
883
|
someElt.append(audio);
|
|
871
|
-
audio.play();
|
|
884
|
+
const playPromise = audio.play();
|
|
885
|
+
playPromise?.catch(() => {
|
|
886
|
+
finish();
|
|
887
|
+
});
|
|
872
888
|
// It feels cleaner if we remove it when done. This could fail, e.g., if the user
|
|
873
889
|
// switches tabs or pages before we get done playing. Removing it immediately
|
|
874
890
|
// prevents the sound being played. It's not a big deal if it doesn't get removed.
|
|
@@ -876,6 +892,17 @@ function playSound(someElt: HTMLElement, soundFile: string, addPrefix = true) {
|
|
|
876
892
|
"ended",
|
|
877
893
|
() => {
|
|
878
894
|
someElt.removeChild(audio);
|
|
895
|
+
finish();
|
|
896
|
+
},
|
|
897
|
+
{ once: true },
|
|
898
|
+
);
|
|
899
|
+
audio.addEventListener(
|
|
900
|
+
"error",
|
|
901
|
+
() => {
|
|
902
|
+
if (audio.parentElement === someElt) {
|
|
903
|
+
someElt.removeChild(audio);
|
|
904
|
+
}
|
|
905
|
+
finish();
|
|
879
906
|
},
|
|
880
907
|
{ once: true },
|
|
881
908
|
);
|