Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### audio_manager.lua ####
- local mgr = {}
- mgr.queue = {}
- mgr.state = "paused"
- local function next(event)
- local fun = table.remove(mgr.queue, 1)
- if fun then
- fun()
- else
- mgr.state = "paused"
- end
- end
- local function resume ()
- if mgr.state == "paused" then
- mgr.state = "running"
- next()
- else
- -- assert(false, "audio playback queue already running")
- end
- end
- function mgr:add (handle, delay, onStart, onEnd)
- delay = delay or 0
- local options = {
- onComplete = function (event)
- if onEnd then onEnd() end
- next(event)
- end
- }
- local fun = function ()
- audio.play(handle, options)
- if onStart then onStart() end
- end
- local player = function ()
- timer.performWithDelay(delay, fun)
- end
- table.insert(self.queue, player)
- resume()
- end
- return mgr
- #### sample usage ####
- local function onSpeakEnd()
- --if(event.completed == true) then
- --print("completed")
- girlmouth:pause()
- girlmouth:setFrame(1)
- --end
- end
- local function onSpeakStart()
- girlmouth:play()
- end
- local function lucySpeaks(handle, delay, callback)
- local onend = onSpeakEnd
- if callback then
- onend = function ()
- onSpeakEnd()
- callback()
- end
- end
- audio_mgr:add(handle, delay, onSpeakStart, onend)
- end
- function issueRequest (delay)
- ....
- local request = audio.loadSound("assets/sound/specific-requests/"..foo.."-"..math.random(3)..".mp3")
- local callback = function ()
- fsm.state = "request-issued"
- end
- lucySpeaks(request, delay, callback)
- --audio.dispose(request)
- ....
- end
- -- say greetings and issue first request
- local intro = audio.loadSound("assets/sound/intro/hi-i-m-lucy-"..math.random(4)..".mp3")
- lucySpeaks(intro)
- issueRequest(700)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement