Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Help with Ebook Template — Gideros Forum

Help with Ebook Template

markusmarkus Member
edited July 2012 in General questions
Hi All
I am modifying Ebook Template --- I want to add music for each page.
So I add
music = Sound.new("sound/page1music.mp3")	
local channel  = music:play(0, 1000)
channel:setVolume(1) 
 
on fisrt page. And
 
music = Sound.new("sound/page2music.mp3")	
local channel  = music:play(0, 1000)
channel:setVolume(1) 
 
for second page.
Problem When I change page from 1 to 2 the first page sound doesn't stop.
And the second one. How can I globally turn off all sounds, for the sound on/off functionality.
Thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    You can modify sceneController either to stop playing music on rightClick, leftClick.

    Or register to scenemanager's "exitBegin" event to stop playing active music
  • markusmarkus Member
    Done!
    Thanks a lot
  • I tried to add voice over to the page, but if you touch the text twice, then the voice is overlapping. How to prevent the voice played twice. Using timer maybe?
  • petecpetec Member
    I've stopped overlap before by getting the sound length before playing the sound in a named channel and then using an enter frame listener to check the playing position using something like:
    self.voiceSnd=Sound.new("soundfile.wav")
    self.soundLength=self.voiceSnd:getLength()
    self.voiceChannel=self.voiceSnd:play()
    self:addEventListener(Event.ENTER_FRAME,self.voiceSpeaking,self)
    and then using the enter frame function to check the playing position and set a boolean 'isPlaying' flag:
    function Scene:voiceSpeaking(e)
    	self.isPlaying=true
    	self.channelPsn=self.voiceChannel:getPosition()
    	if self.channelPsn==self.soundLength then
    		self.isPlaying=false
    		self:removeEventListener(Event.ENTER_FRAME,self.voiceSpeaking,self)
    	end
    end
    I then check the boolean isPlaying when the voice button (or whatever) is tapped and only play the voice if isPlaying is false (i.e. if the sound file isn't already playing). I set self.isPlaying=false in the scene's init function so that the first time I call the voice it plays.

    There is most likely a much simpler way to do all that, but it worked for me :)
  • markusmarkus Member
    Hi
    I have sound on off button each time that user that that I change "sound" boolean variable from true to false and vice versa.
    I need to stop and restart music even user tap that button
    How can I do this ?
    I am playing and stopping musicS when page added to stage (onAddedToStage) and removed from stage (onRemovedFromStage)
    Page3 = gideros.class(Sprite)
     
    function Page3:init()
    self.no = pageNo
    self.music = Sound.new("sound/birds013.wav")
    self.background = Bitmap.new(TextureRegion.new(Texture.new("pages/page3.png", true)))
    self:addChild(self.background)	
    self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self)	
    self:addEventListener(Event.REMOVED_FROM_STAGE, self.onRemovedFromStage, self)
    end
    function Page3:onAddedToStage()
    self.channel = self.music:play(0, 1000)
    self.channel:setVolume(2)
    end
     
    function Page3:onRemovedFromStage()
    self.channel:stop()
    end
  • markusmarkus Member
    P.S. I have different sound files for each of page
Sign In or Register to comment.