[英]Audio file downloads instead of playing
I have a function inside a script file that looks like this: 我在脚本文件中有一个函数,如下所示:
function play()
{
if (paulypower==3){
var embed=document.createElement('object');
embed.setAttribute('type','audio/wav');
embed.setAttribute('data', 'wheelnoise3.m4a');
embed.setAttribute('autostart', true);
document.getElementsByTagName('body')[0].appendChild(embed);
}
else if (paulypower==2){
var embed=document.createElement('object');
embed.setAttribute('type','audio/wav');
embed.setAttribute('data', 'wheelnoise2.m4a');
embed.setAttribute('autostart', true);
document.getElementsByTagName('body')[0].appendChild(embed);
}
else {
var embed=document.createElement('object');
embed.setAttribute('type','audio/wav');
embed.setAttribute('data', 'wheelnoise1.m4a');
embed.setAttribute('autostart', true);
document.getElementsByTagName('body')[0].appendChild(embed);
}
};
When I open the webpage locally, it plays the relevant audio based on the variable paulypower without a problem. 当我在本地打开网页时,它会根据变量paulypower正确播放相关音频。
However, when I upload all files to my web-server and run online - it doesn't play and the browser (Chrome) downloads the file instead. 但是,当我将所有文件上传到Web服务器并在线运行时-它无法播放,而浏览器(Chrome)会下载文件。
Any ideas? 有任何想法吗?
I've got the answer! 我有答案!
I had to configure my .htaccess file on the web-server to define the file type with: 我必须在Web服务器上配置.htaccess文件,以使用以下命令定义文件类型:
AddType audio/wav .m4a
Works like a dream now. 现在像梦一样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.