1

Interesed full load of file with the subsequent possibility of its playing. How to implement full preload of sounds and melodies in javascript?

P.S.: Three I mentioned the word "full".

Softinaria
  • 121
  • 3

1 Answers1

1

you can use HTMLAudioElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement

var audio = new Audio('audio_file.mp3');
audio.play();

UPDATE

there is a callback event "canplaythrough"

var audio = new Audio();
audio.addEventListener('canplaythrough', audio.play , false);

or

use this library: http://goldfirestudios.com/blog/104/howler.js-Modern-Web-Audio-Javascript-Library

var sound = new Howl({
  urls: ['sound.mp3', 'sound.ogg']
}).play();
WalksAway
  • 2,769
  • 2
  • 20
  • 42
  • `HTMLAudioElement` does not load the entire file. Only informs about the possibility of him playing. I need the whole file. Thrice wrote about it. `howler.js` need look. At first glance, it loading by xhr. But I would like to do without the extra libraries. It may be handy to get from code. Thanks. – Softinaria Aug 11 '16 at 07:31
  • for update: canplaythrough - CAN PLAY THROUGH - It determines whether the sound should play. But this does not mean that it will be loaded. Instead, have decided that they will have time him at the right moment to download. But it is not so - not enough time. P.S.: replay is already under way without delay - the sound is loaded. – Softinaria Aug 11 '16 at 07:56