Use AudioSystem in Display

This commit is contained in:
toasted-nutbread 2020-03-07 13:18:48 -05:00
parent 110e561eae
commit e048a1efce

View File

@ -19,8 +19,7 @@
/*global docRangeFromPoint, docSentenceExtract /*global docRangeFromPoint, docSentenceExtract
apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd
apiScreenshotGet, apiForward apiScreenshotGet, apiForward
audioPrepareTextToSpeech, audioGetFromSources AudioSystem, DisplayGenerator, WindowScroll, DisplayContext, DOM*/
DisplayGenerator, WindowScroll, DisplayContext, DOM*/
class Display { class Display {
constructor(spinner, container) { constructor(spinner, container) {
@ -32,7 +31,7 @@ class Display {
this.index = 0; this.index = 0;
this.audioPlaying = null; this.audioPlaying = null;
this.audioFallback = null; this.audioFallback = null;
this.audioCache = new Map(); this.audioSystem = new AudioSystem();
this.styleNode = null; this.styleNode = null;
this.eventListeners = new EventListenerCollection(); this.eventListeners = new EventListenerCollection();
@ -364,7 +363,6 @@ class Display {
this.updateDocumentOptions(this.options); this.updateDocumentOptions(this.options);
this.updateTheme(this.options.general.popupTheme); this.updateTheme(this.options.general.popupTheme);
this.setCustomCss(this.options.general.customPopupCss); this.setCustomCss(this.options.general.customPopupCss);
audioPrepareTextToSpeech(this.options);
} }
updateDocumentOptions(options) { updateDocumentOptions(options) {
@ -775,16 +773,16 @@ class Display {
} }
const sources = this.options.audio.sources; const sources = this.options.audio.sources;
let {audio, source} = await audioGetFromSources(expression, sources, this.getOptionsContext(), false, this.audioCache); let audio, source, info;
let info; try {
if (audio === null) { ({audio, source} = await this.audioSystem.getExpressionAudio(expression, sources, this.getOptionsContext()));
info = `From source ${1 + sources.indexOf(source)}: ${source}`;
} catch (e) {
if (this.audioFallback === null) { if (this.audioFallback === null) {
this.audioFallback = new Audio('/mixed/mp3/button.mp3'); this.audioFallback = new Audio('/mixed/mp3/button.mp3');
} }
audio = this.audioFallback; audio = this.audioFallback;
info = 'Could not find audio'; info = 'Could not find audio';
} else {
info = `From source ${1 + sources.indexOf(source)}: ${source}`;
} }
const button = this.audioButtonFindImage(entryIndex); const button = this.audioButtonFindImage(entryIndex);