How to increase audio download speed using JavaScript?

I created code to play the .mp3 file using JavaScript. But the file takes a long time to play on Android. I want to quickly play sound after clicking on a text image. How to increase download speed on Android?

My JavaScript code is:

 if(window.audio) { audio.pause(); } window.audio = new Audio (audio_path); window.audio.play(); 

Check out the demo here - http://97.74.195.122/gizmo-demo/canvasslidertwo.php

In the link above, click the Japanese word for sound.

+5
source share
1 answer

In fact, you are facing the error depicted in this question . This allows Chrome browsers to update files from the Audio Element every time you change its src property (without caching).

One solution would be to use WebAudioAPI and store your audio files in a buffer. By doing so, you can call them without latency. You can check the accepted answer for an example on how to deal with this.

Or you can also try not to call a new sound () for each click and, rather, download all the audio files from your page and only call their play() method when clicked. But I'm not sure if this will fix your problem.

+1
source

All Articles