Let's simulate our own little music player by creating user interface buttons that will control the audio calls:
In the
Chapter 6
folder, copy theControlling Audio
project folder to your desktop. You will notice several art assets, aui.lua
library and asong2.mp3
file inside. You can download the project files accompanying this book from the Packt website:In the same project folder, create a brand new
main.lua
file.Load the audio file via
loadStream()
, name itbackgroundSound
, and call the UI library. Also add in a local variable calledmyMusic
:local ui = require("ui") local backgroundSound = audio.loadStream("song2.mp3") local myMusic
Create a local function called
onPlayTouch()
with an event parameter to play the audio file. Add anif
statement that containsevent.phase == "release"
, so that the music starts playing upon button release. Apply theplayBtn
display object as a new UI button:local onPlayTouch = function( event ) if event.phase == "release...