Game Development Reference
In-Depth Information
document.body.appendChild(soundTwo);
Although the JavaScript Audio object may seem easier to deal with, especially since
it takes that awesome constructor argument that saves us a whole line of code, they
both behave exactly the same, and can only be told apart at run time if you really
want to be picky and distinguish them from each other. One small detail that you
should know is that when we create that audio reference in JavaScript, it is not ne-
cessary to append it to the DOM in order to play the file.
However you decide to approach this setup step, once we have a reference to an
audio object in JavaScript, we can control it with any one of the many events and
attributes associated with the object. The audio objects are as follows:
play() : It starts playing the file.
pause() : It stops playing the file, and maintains the currentTime.
paused : Is a Boolean representing the current play state.
canPlayType : Is used to find out whether the browser supports a partic-
ular audio type.
currentSrc : It returns the absolute path to the file currently assigned to
the object.
currentTime : It returns the current play position in seconds, as a floating
point number.
duration : It returns the total play time in seconds, as a floating point num-
ber.
ended : Is a Boolean indicating whether the currentTime is equal to dura-
tion.
readyState : It indicates the state of the download of the source file.
volume : It indicates the current volume of the file, ranging from 0 to 1
both inclusive. This number is relative to the current system volume.
Search WWH ::




Custom Search