Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
HTML5 Javascript API for audio
Old 10-13-2010, 05:09 AM HTML5 Javascript API for audio
Banned

Posts: 408
Name: mushget
Trades: 0
My question is about the HTML5 Javascript API for the <audio> tag.

I have a js file that dynamically generates <audio> elements in response to Ajax calls. The relevant part looks something like this:

Code:
 var soundNames = new Array();
      var soundDiv = document.getElementById("sound");
      for(var i=0; i<JSONResponse.length; i++){
        soundNames[i] = getWord(JSONResponse[i][4]) + i;
        var sound = document.createElement("audio");
        sound.setAttribute("src", "sound/" + JSONQuestion[0] + ".mp3");
        sound.setAttribute("preload", "auto");
        sound.setAttribute("id", soundNames[i]);
        soundDiv.appendChild(sound);
      }
I found that despite setting preload to "auto", nothing was preloaded.
I realize this is probably because the call happens after the page is loaded (?)

I went looking for an API call I can use to preload these sounds and found this on a site:
Code:
audioElement.addEventListener(“load”, function() {
audioElement.play();
$(“.duration span”).html(audioElement.duration);
$(“.filename span”).html(audioElement.src);
}, true);
It looks the goods but I don't know JQuery. Can someone give me a plain JS version?
More generally, what are the api methods? load()? Why is play() called above.
Also what events can I listen in to to hear when the loading has completed.

Looking forward to your help.
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
 
Register now for full access!
Reply     « Reply to HTML5 Javascript API for audio
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.07774 seconds with 12 queries