Is there a way to catch the completion of an audio file upload event?

I would like to catch a browser event that tells me when the WAV file resource has successfully finished loading into the browser cache.

With such an event, I can lay out the text on the page while the file is loading, asking the user to be patient for his arrival. In the end, they expect to listen to the file immediately, but this will not happen if the file is already in the cache (from previous visits to the page). After the event, I can issue a message stating that the music is ready to play, etc.

IE uses BGSOUND, which is a patented feature invented by Microsoft, and it does not fire any events (you can expect that "onload" will be one, but it will not). Sound objects in Javascript can be created, but ... there seems to be no way to catch a browser event that tells you when a sound file (such as a WAV file) has finished loading.

I would like to make any decision, especially if it is related to Javascript. Please note that the β€œobvious” Page Load event is not enough, because it does not occur at the granular level that I need.

Also note that I successfully download and play music files in IE and Firefox with my current Javascript code, but I would really like to improve my user interface with messages that cause them patience while they wait for large music files to load.

+5
source share
2 answers

If you are free to enable SoundManager2 , each individual sound clip has an event onloadand a property readyState. He also received an event whileloadingthat fires periodically during data loading.

, Flash- ( , HTML5 Audio, ), MP3/MP4.

, SM2 - , .

+1

, WAV: API HTML5, :

var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'backgroundsound.ogg');
audioElement.load()
audioElement.addEventListener("load", function() {
    alert('Loading done!')
    audioElement.play();
}, true);

, ogg (vorbis) mp3.

+1

All Articles