How to play wav file in web browser using javascript on ipad

I am creating a simulator that runs in a browser and needs to be deployed on an iPad. I ran into a problem when I need to be able to play a WAV file when I click a button.

I know that the ipad supports HTML5 audio text, but this application will work on PC, Mac and iPad, and all browsers do not yet support HTML5 audio text. So I really need a solution that will work on the ipad as well as on the desktop.

Thank you in advance for your help in resolving this issue.

I know that it’s not better to use audio files on web pages, but this is what the customer ordered and he is the one who pays the bills.

+4
source share
2 answers
<object type="audio/mpeg" data="muzak.mp3">Your browser doesn't seem to like MP3s</object> 

which should run any plugin registered for mpeg audio, or display alternative text.

You better embed mp3, because support for this is very common. For .wav, by comparison, there could be anything. Wav is a container format and can use any number of different codecs, most of which are probably NOT supported by your average computer / browser.

+1
source

JavaScript:

 var audio = new Audio("noise.mp3"); audio.play(); 

I heard, however, that iOS devices (iPad, iPhone, iPod) turned off autoplay and JavaScript.play () at startup and will only play noise in response to an explicit user action.

Google "HTML5 audio" for details (and there are many details.)

+4
source

Source: https://habr.com/ru/post/1369238/


All Articles