summaryrefslogtreecommitdiff
path: root/ext/mixed/js/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 13:18:48 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 21:42:18 -0500
commite048a1efce5931a3aab4a8a068ee6f5ec9805ce8 (patch)
treef14865710749819e1ae432ff2634239860797eea /ext/mixed/js/display.js
parent110e561eae9d7a892a55f904d63a4f5ca08fae0f (diff)
Use AudioSystem in Display
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r--ext/mixed/js/display.js16
1 files changed, 7 insertions, 9 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 6a762a65..e0b12f7d 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -19,8 +19,7 @@
/*global docRangeFromPoint, docSentenceExtract
apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd
apiScreenshotGet, apiForward
-audioPrepareTextToSpeech, audioGetFromSources
-DisplayGenerator, WindowScroll, DisplayContext, DOM*/
+AudioSystem, DisplayGenerator, WindowScroll, DisplayContext, DOM*/
class Display {
constructor(spinner, container) {
@@ -32,7 +31,7 @@ class Display {
this.index = 0;
this.audioPlaying = null;
this.audioFallback = null;
- this.audioCache = new Map();
+ this.audioSystem = new AudioSystem();
this.styleNode = null;
this.eventListeners = new EventListenerCollection();
@@ -364,7 +363,6 @@ class Display {
this.updateDocumentOptions(this.options);
this.updateTheme(this.options.general.popupTheme);
this.setCustomCss(this.options.general.customPopupCss);
- audioPrepareTextToSpeech(this.options);
}
updateDocumentOptions(options) {
@@ -775,16 +773,16 @@ class Display {
}
const sources = this.options.audio.sources;
- let {audio, source} = await audioGetFromSources(expression, sources, this.getOptionsContext(), false, this.audioCache);
- let info;
- if (audio === null) {
+ let audio, source, info;
+ try {
+ ({audio, source} = await this.audioSystem.getExpressionAudio(expression, sources, this.getOptionsContext()));
+ info = `From source ${1 + sources.indexOf(source)}: ${source}`;
+ } catch (e) {
if (this.audioFallback === null) {
this.audioFallback = new Audio('/mixed/mp3/button.mp3');
}
audio = this.audioFallback;
info = 'Could not find audio';
- } else {
- info = `From source ${1 + sources.indexOf(source)}: ${source}`;
}
const button = this.audioButtonFindImage(entryIndex);