We're going to learn how sound effects and music are implemented in Corona to get an idea of how it really works. To play an audio follow the steps:
Create a new project folder on your desktop called
Playing Audio
.In the
Chapter 6 Resources
folder, copy thering.wav
andsong1.mp3
sound files into your project folder and create a newmain.lua
file. You can download the project files that accompany this book from the Packt Publishing website.Preload the following audio with
loadSound()
andloadStream()
:ringSound = audio.loadSound( "ring.wav" ) backgroundSound = audio.loadStream( "song1.mp3" )
Play
backgroundSound
by setting it to channel 1, loop it infinitely, and fade in after 3 seconds:mySong = audio.play( backgroundSound, { channel=1, loops=-1, fadein=3000 } )
Add in
ringSound
and play it once:myRingSound = audio.play( ringSound )
Save and run the project in the Corona Simulator to hear the results.