Sound Issue

Hi,

I’m new to Lua and Android game development and I have a problem getting sound to play.

I made it so sound would play when the “bombTouched” and “balloonTouched” events were triggered

unfortunately once touched they do not play any audio

This is my main.lua so far

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- --Add menu -- Start the physics engine local physics = require( "physics" ) physics.start() -- Calculate half the screen width and height halfW = display.contentWidth\*0.5 halfH = display.contentHeight\*0.5 -- Set the background local bkg = display.newImage( "night\_sky.png", halfW, halfH ) -- Score score = 0 scoreText = display.newText(score, halfW, 10) --declare sounds local bombPop = audio.loadSound("sounds/bombPop.wav") local balloonPop = audio.loadSound("sounds/balloonPop.wav") --Add background music -- Define music variables local gameMusic = audio.loadStream( "sounds/gamemusic.mp3" ) -- Play the music local gameMusicChannel = audio.play( gameMusic, { loops = -1 } ) -- Called when the balloon is tapped by the player -- Increase score by 1 local function balloonTouched(event) if ( event.phase == "began" ) then Runtime:removeEventListener( "enterFrame", event.self ) event.target:removeSelf() score = score + 1 scoreText.text = score audio.play =balloonPop end end -- Called when the bomb is tapped by the player -- Half the score as a penalty local function bombTouched(event) if ( event.phase == "began" ) then Runtime:removeEventListener( "enterFrame", event.self ) event.target:removeSelf() score = math.floor(score \* 0.5) scoreText.text = score audio.play =bombPop end end ---------------------------------------- -- Delete objects which has fallen off the bottom of the screen local function offscreen(self, event) if(self.y == nil) then return end if(self.y \> display.contentHeight + 50) then Runtime:removeEventListener( "enterFrame", self ) self:removeSelf() end end -- Add a new falling balloon or bomb local function addNewBalloonOrBomb() -- You can find red\_ballon.png and bomb.png in the GitHub repo local startX = math.random(display.contentWidth\*0.1,display.contentWidth\*0.9) if(math.random(1,5)==1) then -- BOMB! local bomb = display.newImage( "bomb.png", startX, -300) physics.addBody( bomb ) bomb.enterFrame = offscreen Runtime:addEventListener( "enterFrame", bomb ) bomb:addEventListener( "touch", bombTouched ) else -- Balloon local balloon = display.newImage( "red\_balloon.png", startX, -300) physics.addBody( balloon ) balloon.enterFrame = offscreen Runtime:addEventListener( "enterFrame", balloon ) balloon:addEventListener( "touch", balloonTouched ) end end -- Add a new balloon or bomb now addNewBalloonOrBomb() -- Keep adding a new balloon or bomb every 0.5 seconds timer.performWithDelay( 500, addNewBalloonOrBomb, 0 )

Hi @ultimaterex.business,

Just curious, do any sounds work? Does the background music play? Do the sounds which “fail” do so (fail) in both the Corona Simulator and on an actual device?

Best regards,

Brent

The Background music does indeed play,

The “BalloonPop” and “BombPop” sounds fail on emulator and actual Android device running 4.4.2

Can you try just playing those sounds outright, in some lines of code, totally outside of the touch handler function?

Thank you for the help,

I fixed the issue by using soundtable

Hi @ultimaterex.business,

Just curious, do any sounds work? Does the background music play? Do the sounds which “fail” do so (fail) in both the Corona Simulator and on an actual device?

Best regards,

Brent

The Background music does indeed play,

The “BalloonPop” and “BombPop” sounds fail on emulator and actual Android device running 4.4.2

Can you try just playing those sounds outright, in some lines of code, totally outside of the touch handler function?

Thank you for the help,

I fixed the issue by using soundtable