diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-03-07 21:44:51 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-07 21:44:51 -0500 | 
| commit | d022d61b1a66614e1837585afcb53a25253b643a (patch) | |
| tree | 40659359b076fed2ad57980f88e26d2ff95a12c5 /ext/mixed/js/display.js | |
| parent | b8eb5e6016834cc751c973239e1e4604fe9799ee (diff) | |
| parent | dceaa853098a465b2eaa1b90900b5c1832131f26 (diff) | |
Merge pull request #399 from toasted-nutbread/audio-system-refactor
Audio system refactor
Diffstat (limited to 'ext/mixed/js/display.js')
| -rw-r--r-- | ext/mixed/js/display.js | 23 | 
1 files changed, 13 insertions, 10 deletions
| diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 6a762a65..3fe8e684 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -18,9 +18,8 @@  /*global docRangeFromPoint, docSentenceExtract  apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd -apiScreenshotGet, apiForward -audioPrepareTextToSpeech, audioGetFromSources -DisplayGenerator, WindowScroll, DisplayContext, DOM*/ +apiScreenshotGet, apiForward, apiAudioGetUrl +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({getAudioUri: this._getAudioUri.bind(this)});          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.getDefinitionAudio(expression, sources)); +                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); @@ -918,4 +916,9 @@ class Display {          const key = event.key;          return (typeof key === 'string' ? (key.length === 1 ? key.toUpperCase() : key) : '');      } + +    async _getAudioUri(definition, source) { +        const optionsContext = this.getOptionsContext(); +        return await apiAudioGetUrl(definition, source, optionsContext); +    }  } |