From 701c91ea66852631ccc6e7bfb23b49578646ff33 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 11 Feb 2017 12:16:14 -0800 Subject: block placeholder audio with a short audio clip --- ext/fg/js/frame.js | 23 +++++++++++++++++++---- ext/fg/mp3/button.mp3 | Bin 0 -> 17735 bytes ext/manifest.json | 5 +++-- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 ext/fg/mp3/button.mp3 diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js index 83d6d7ef..ca0636f9 100644 --- a/ext/fg/js/frame.js +++ b/ext/fg/js/frame.js @@ -170,12 +170,27 @@ class Frame { } for (const key in this.audioCache) { - this.audioCache[key].pause(); + const audio = this.audioCache[key]; + if (audio !== null) { + audio.pause(); + } } - const audio = this.audioCache[url] || new Audio(url); - audio.currentTime = 0; - audio.play(); + let audio = this.audioCache[url]; + if (audio) { + audio.currentTime = 0; + audio.play(); + } else { + audio = new Audio(url); + audio.onloadeddata = () => { + if (audio.duration === 5.694694) { + audio = new Audio('mp3/button.mp3'); + } + + this.audioCache[url] = audio; + audio.play(); + }; + } } handleError(error) { diff --git a/ext/fg/mp3/button.mp3 b/ext/fg/mp3/button.mp3 new file mode 100644 index 00000000..7a9728d1 Binary files /dev/null and b/ext/fg/mp3/button.mp3 differ diff --git a/ext/manifest.json b/ext/manifest.json index 1c80435f..0a1301c1 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Yomichan", - "version": "1.0.12", + "version": "1.0.13", "description": "Japanese dictionary with Anki integration", "icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"}, @@ -31,13 +31,14 @@ ], "web_accessible_resources": [ "fg/css/frame.css", + "fg/frame.html", "fg/img/add_kanji.png", "fg/img/add_term_kana.png", "fg/img/add_term_kanji.png", "fg/img/play_audio.png", "fg/img/spinner.gif", "fg/js/frame.js", - "fg/frame.html", + "fg/mp3/button.mp3", "fg/ttf/kanji-stroke-orders.ttf", "fg/ttf/vl-gothic-regular.ttf" ] -- cgit v1.2.3