can audio be played with the book section of director?

Hello,
I have a couple questions about the director class. First off I have used the book template in version 1.4. I am wondering if there is a way to load audio files that correspond to each page for a “read to me” section available to turn on or off in the “settings” screen which I would like to use in a popup.

I am wondering if there is a way to not only turn on the read to me from the start, but to also select a “read to me” button from a popup no matter where you are in the book.

I am guessing you would have to read from the app what “page” you are on and start the correct audio file to play from there, then have each respective audio file play with the corresponding “swipe” you make to turn a page.

Please forgive me if I pasted this wrong as this is the first time I am pasting code into the forum.

I have pasted sections of the main.lua, pages.lua, screen3.lua, and intro.lua to see if anyone has help or suggestions. Or if anyone can answer whether or not this is even possible.

I am very new to this and have been muttling my way through and have made it thus far on all the great people in the Corona community willing to help. Thank you all for taking time in a volunteer capacity to help others. I hope some day to be proficient enough to help others.

Main
< lua >
display.setStatusBar( display.HiddenStatusBar )

–==========
– GLOBALS
–==========

_W = display.contentWidth
_H = display.contentHeight

–==========
– IMPORTS
–==========

local director = require( “director” )

–==========
– PAGES
–==========


– PAGE LIST

– page: name of the scene
– params: parameters to send to the scene

pageList = {
{ page = “pages”, params = { image = “Page1.png”, name = “Page1” } },
{ page = “pages”, params = { image = “Page2.png”, name = “Page2” } },
{ page = “pages”, params = { image = “Page3.png”, name = “Page3” } },
{ page = “pages”, params = { image = “Page4.png”, name = “Page4” } },
{ page = “pages”, params = { image = “Page5.png”, name = “Page5” } },
{ page = “pages”, params = { image = “Page6.png”, name = “Page6” } },
{ page = “pages”, params = { image = “Page7.png”, name = “Page7” } },
{ page = “pages”, params = { image = “Page8.png”, name = “Page8” } },
{ page = “pages”, params = { image = “Page9.png”, name = “Page9” } },
{ page = “pages”, params = { image = “Page10.png”, name = “Page10” } },
{ page = “pages”, params = { image = “Page11.png”, name = “Page11” } },
{ page = “pages”, params = { image = “Page12.png”, name = “Page12” } },
{ page = “pages”, params = { image = “Page13.png”, name = “Page13” } },
{ page = “pages”, params = { image = “Page14.png”, name = “Page14” } },
{ page = “pages”, params = { image = “Page15.png”, name = “Page15” } },
{ page = “pages”, params = { image = “Page16.png”, name = “Page16” } },
}

–==========
– BEGIN
–==========


– Go to intro

director:changeScene ( “intro” )
< /lua >

Intro
< lua >
module(…, package.seeall)

–===========
– SCENE: INTRO
–===========
function new()


– DISPLAY GROUPS

local localGroup = display.newGroup()


– TITLE eventually replaced with the sentient lab and scott spinks logos

local title = display.newText( “Bone Tree”, 0, 0, nil, 40 )
title:setReferencePoint( display.CenterReferencePoint )
title.x = _W / 2
title.y = _H / 2
localGroup:insert( title )


– PICTURES CREDITS

local picCred = display.newText( “Artwork and Story by Scott Spinks www.scottspinks.com”, 0, 0, nil, 20 )
picCred:setTextColor( 255, 255, 255 )
picCred:setReferencePoint( display.CenterReferencePoint )
picCred.x = _W / 2
picCred.y = _H / 4 * 3 -40
localGroup:insert( picCred )

local goSpinks = function ( event )
if event.phase == “ended” then
system.openURL( “http://www.scottspinks.wordpress.com/” )
end
end
picCred:addEventListener( “touch”, goSpinks )


– APP CREDITS

local appCred = display.newText( “Developed by Lenny Hubbard of Sentient Lab www.sentientlab.com”, 0, 0, nil, 20 )
appCred:setTextColor( 255, 255, 255 )
appCred:setReferencePoint( display.CenterReferencePoint )
appCred.x = _W / 2
appCred.y = _H / 4 * 3
localGroup:insert( appCred )

local goSentientLab = function ( event )
if event.phase == “ended” then
system.openURL( “http://sentientlab.com/” )
end
end
appCred:addEventListener( “touch”, goSentientLab )


– BACKGROUND

local background = display.newRect( 0, 0, _W, _H )
background:setFillColor( 0, 0, 0 )
background.x = _W / 2
background.y = _H / 2
localGroup:insert( background )


– VARIABLES

local showFx
local fxTime = 2000
local safeDelay = 50


– CREATE BOOK

local function createBook ( event )


– TURN TO BOOK

director:turnToBook ()


– CREATE BOOK

director:newBookPages( pageList )

end


– FADE EFFECT

local endFade = function ()
showFx = transition.to ( background, { alpha = 1, time = fxTime, delay = fxTime * 2, onComplete = createBook } )
end

showFx = transition.to ( background, { alpha = 0, time = fxTime, onComplete = endFade } )


– RETURN

return localGroup

end
< /lua>

Pages
< lua >
module(…, package.seeall)

–===========
– BOOK PAGES
–===========

new = function ( params )


– Groups

local localGroup = display.newGroup()


– Image

local image = display.newImageRect( params.image, _W, _H )
image.x = _W / 2
image.y = _H / 2
localGroup:insert( image )


–Home Button

local homeButton = display.newImage (“HomeBW.png”)
homeButton:setReferencePoint( display.TopRightReferencePoint )
homeButton.x = 1020 --fix the x and y to be relative and not hard coded
homeButton.y = 10
localGroup:insert( homeButton )


local gohomeButton = function ( event )
if event.phase == “ended” then
director:turnToScenes()
director:changeScene ( “intro” )
end
end
homeButton:addEventListener( “touch”, gohomeButton )


–Settings Button Pop up

local settingsButton = display.newImage (“SettingsBW.png”)
settingsButton:setReferencePoint( display.TopLeftReferencePoint )
settingsButton.x = 10 – fix the x and y to be relative an not hard coded
settingsButton.y = 17
localGroup:insert( settingsButton )


local gosettingsButton = function ( event )
if event.phase == “ended” then
director:openPopUp( “screen3”, popClosed)
end
end
settingsButton:addEventListener( “touch”, gosettingsButton )


– On Close


– Show current page

localGroup.start = function()
print( "Current page: " … params.name )
end


– MUST return a display.newGroup()

return localGroup

end
< /lua>

Screen3 aka popup
< lua >
module(…, package.seeall)

–=============
– POP UP: SCREEN 3
–=============

new = function ()


– Groups

local localGroup = display.newGroup()


– Display Objects

local w, h = display.contentWidth, display.contentHeight
local background = display.newImage( “PopUpBackground.png” )
background.x = 512
background.y = 375

local title = display.newText( “Close”, 0, 0, native.systemFontBold, 16 )

local readToMe = display.newImage( “bt_popup.png” )
readToMe.x = 512
readToMe.y = 500

– Listeners

local touched = function ( event )
if event.phase == “ended” then
director:closePopUp()
end
end

local touched2 = function ( event ) --can’t change scene inside of a popup, need to create a function that will load audio according to what page you are on
if event.phase == “ended” then
director:turnToScenes()
director:changeScene ( “intro” )
end
end

–============
– INITIALIZE
–============

local function initVars ()


– Inserts

localGroup:insert( background )
localGroup:insert( title )
localGroup:insert( readToMe )

– Positions

title.x = 512
title.y = 600


– Colors

title:setTextColor( 255,255,255 )


– Listeners

title:addEventListener ( “touch”, touched )
readToMe:addEventListener ( “touch”, touched2 )

end


– Initiate variables

initVars()


– MUST return a display.newGroup()

return localGroup

end
< /lua >
[import]uid: 15962 topic_id: 17127 reply_id: 317127[/import]

there is nothing that suggests that it cannot be.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 17127 reply_id: 64421[/import]

Jayant, that is great news that it is at least theoretically possible. I guess my next question would be how I could go about doing it. I have scoured the forums and can’t find even a nugget of info about it. Any help you could give in what possible solutions to pull this off would be helpful. I like the challenge of figuring stuff out, but am at a standstill with no idea of what I should even be attempting. Thanks in advance!!

As long as I am fully groveling for help, I am wondering if someone can help with how to correctly post code… I noticed when I attempted to post code with the lua tags I didn’t get what I was expecting and don’t want to post walls of text. I see people post what looks like screen shots of an editor with line numbers and scrolling capability on it. How is that done? [import]uid: 15962 topic_id: 17127 reply_id: 64507[/import]

Just copy and paste your code here between these:

[text][lua] your code snippet here … [/lua][/text]
Regards, [import]uid: 89165 topic_id: 17127 reply_id: 64514[/import]