Introduction :
While developing a gaming application, everyone wants to add background music to play all the time when user is playing the game.
Corona sdk provides API that simply plays the music using 1 line of code.
Description :
Let’s take a scenario. We have a game board page, where user plays the game and while playing a background music plays all the time.
Let’s make the main.lua file which is the landing page of any application that are made by Corona SDK
CODE BLOCK :
main.lua -- Code to hide the status bar display.setStatusBar( display.HiddenStatusBar ) -- Give background color to the all pages of the application display.setDefault( 'background', 0, 0, 255 ); -- Define music variables local gameMusic = audio.loadStream( "sounds/gamemusic.mp3" ) -- Play the music local gameMusicChannel = audio.play( gameMusic, { loops = -1 } )
On above code you can see that we have defined a variable ‘gameMusic’ where we have aalso ssigned music using audio API which called the loadstream function to load the music stream.
And then I have used the function ‘audio.play’ which accept playing stream that need to play and a table that accepts the various option. Here I have passed only one option i.e. loops where I have assigned ‘-1’ which indicates that the music will play infinite time.
Summary :
On above discussion we learn about, how easily we can play misic continiously in an app page using corona sdk.
NOTE : Have checked on Android devices.