We're going to listen to how sound effects and music are implemented in Corona to get an idea of how it really works:
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 accompanying this book from the Packt 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 for 3 seconds:mySong = audio.play(backgroundSound, {channel=1, loops=-1, fadein=3000})
Add in
ringSound
and have it played once:myRingSound = audio.play(ringSound)
Save and run the project in the Corona simulator to hear the results.