I have a list of vocabulary (ex. http://nihongoup.com/vocabulary/animals/) where each word is associated with an audio file whose name is composed of the kanji for the word (first column in the list) and it's reading in hiragana (second column). For example, the audio file for 動物 is called 動物_どうぶつ (mp3 and wav).
Audio button code:
<span onclick="playAudio('/files/audio/words/動物_どうぶつ');" class="btn-audio"></span>
JavaScript that embeds the audio file:
var audioEmbed = null;
function playAudio(which)
{
if (audioEmbed)
{
document.body.removeChild(audioEmbed);
audioEmbed.removed = true;
audioEmbed = null;
}
audioEmbed = document.createElement("audio");
var mp3Embed = document.createElement("source");
mp3Embed.setAttribute("src", which + ".mp3");
mp3Embed.setAttribute("type", "audio/mpeg");
audioEmbed.appendChild(mp3Embed);
var wavEmbed = document.createElement("source");
wavEmbed.setAttribute("src", which + ".wav");
wavEmbed.setAttribute("type", "audio/x-wav");
audioEmbed.appendChild(wavEmbed);
audioEmbed.setAttribute("autoplay", true);
audioEmbed.removed = false;
document.body.appendChild(audioEmbed);
}
For some reason, the audio plays fine in all browsers except Firefox. If I change the name of the files to something written in Latin characters, the sound plays fine too. Is this a bug in Firefox and is there any way of solving this problem? Thanks!