HTML and CSS Reference
In-Depth Information
Playing the Sound
Finally, we get to the point where we can play a sound inside our
canvasApp()
function. Be-
cause we preloaded the sound originally outside the context of this function into a variable
with a global scope, we just need to call the
play()
function
audioElement
to start playing
the sound:
audioElement
.
play
();
Figure 7-4
shows what this Canvas application will look like when executed in an
HTML5-compliant web browser. (Notice that we have left the display of the audio properties
in this application.)
Figure 7-4. Sound loaded and played “on” the canvas