Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有日语文件名的音频文件不';不要在Firefox中玩_Javascript_Firefox_Html_Unicode_Audio - Fatal编程技术网

Javascript 带有日语文件名的音频文件不';不要在Firefox中玩

Javascript 带有日语文件名的音频文件不';不要在Firefox中玩,javascript,firefox,html,unicode,audio,Javascript,Firefox,Html,Unicode,Audio,我有一个词汇表(例如),其中每个单词都与一个音频文件相关联,该文件的名称由该单词的汉字组成(列表中的第一列),并以平假名读取(第二列)。例如,音频文件動物 被称为動物_どうぶつ (mp3和wav) 音频按钮代码: 嵌入音频文件的JavaScript: var audioEmbed = null; function playAudio(which) { if (audioEmbed) { document.body.removeChild(audioEmbed);

我有一个词汇表(例如),其中每个单词都与一个音频文件相关联,该文件的名称由该单词的汉字组成(列表中的第一列),并以平假名读取(第二列)。例如,音频文件動物 被称为動物_どうぶつ (mp3和wav)

音频按钮代码:

嵌入音频文件的JavaScript:

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);
}

出于某种原因,除了Firefox之外,所有浏览器都可以播放音频。如果我把文件名改成拉丁字符,声音也会很好。这是Firefox中的一个bug吗?有没有办法解决这个问题?谢谢

试试JavaScript函数encodeURI(),例如:


看起来这些WAV文件被编码为24位单声道PCM。Firefox的WAV解码器只支持8位和16位PCM编码,因此无法播放这些文件。看

应该与文件名无关;也许您测试的拉丁文件名指向具有不同编码的WAV文件


“简单”的解决方案是将所有涉及的WAV文件转换为16位PCM…

当我尝试直接加载某个音频文件的url(或我认为是url)时,我会得到一个HTML“定价”页面。playAudio函数实际上对字符串做了什么?音频文件的实际URL是什么?对不起。。。我用代码示例更新了我的问题。
動物_どうぶつ是。您是否尝试过对字符进行百分比编码?我只是尝试了对URL进行编码,但没有解决问题:(@Philip:您是否使用了
escape
encodeURIComponent
?前者在非ascii字符上无法正常工作。
encodeURIComponent
应该使用,
escape
被弃用,因为它不能处理非ascii字符。不幸的是,这没有帮助。FireFox仍然保持沉默:(您已经设置了HTML文档的编码?如果未设置,DOM模型可能会默认为latin-1。出于某种原因,如果我使用encodeURIComponent(例如,
wavEmbed.setAttribute(“src”,encodeURIComponent(which+“.wav”);
)它在Opera中也停止工作。@Philip:对不起,在再次查看您的代码后,您想要的是
encodeURI
:-)
encodeURIComponent
将对URL中的路径分隔符
/
进行编码。对于略读问题,我很满意!非常感谢!这确实是个问题:)
    var mp3Embed = document.createElement("source");  
    mp3Embed.setAttribute("src", encodeURI(which + ".mp3"));