简体   繁体   中英

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.

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.

Any ideas?

I've got the answer!

I had to configure my .htaccess file on the web-server to define the file type with:

AddType audio/wav .m4a

Works like a dream now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM