aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-06-14 20:33:19 -0700
committerAlex Yatskov <alex@foosoft.net>2016-06-14 20:44:38 -0700
commitb91c79e321f8022ee53903cffead04ed4d4760e6 (patch)
treed8820c546635dc6801d43883803abafd7a7a84db /ext
parentad617221308b04e8f26ec52d876603e7aec3a03d (diff)
Cache audio samples
Diffstat (limited to 'ext')
-rw-r--r--ext/fg/js/client.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index 5b8cfe29..1f77ed95 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -20,7 +20,7 @@
class Client {
constructor() {
this.popup = new Popup();
- this.audio = null;
+ this.audio = {};
this.lastMousePos = null;
this.lastRange = null;
this.activateKey = 16;
@@ -172,12 +172,15 @@ class Client {
const dfn = this.definitions[index];
const url = `http://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kana=${dfn.reading}&kanji=${dfn.expression}`;
- if (this.audio !== null) {
- this.audio.pause();
+ for (let key in this.audio) {
+ this.audio[key].pause();
}
- this.audio = new Audio(url);
- this.audio.play();
+ const audio = this.audio[url] || new Audio(url);
+ audio.currentTime = 0;
+ audio.play();
+
+ this.audio[url] = audio;
}
api_displayKanji(kanji) {